You say that the await keyword can only be used with functions that were declared with async.
Jerry Krusinski
3

You can await on a function that returns a promise, but the await keyword itself must be in a function that’s declared async.

For example, this works:

const sleep = ms => new Promise(res => setTimeout(res, ms));
async function trySleep() {
 console.log(‘starting’);
 await sleep(5000);
 console.log(‘done’);
}
trySleep();

Show your support

Clapping shows how much you appreciated Ed Gauci’s story.