What is the point of this design? It makes no sense to me.
If we are allowed to use await on the top level, we should also be able to use await inside a normal function. Yes I know it will make the function blocking, which is exactly the desired behaviour.
function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
// works
print("bef");
await sleep(1000); // blocking
print("aft");
async function asyncsleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
// works
print("bef");
await asyncsleep(1000); // blocking
print("aft");