You can only usefully await
a promise.
setTimeout
returns a timeout id (a number) that you can pass to clearTimeout
to cancel it. It doesn’t return a promise.
You could wrap setTimeout
in a promiseā¦
async function test() {
await new Promise( resolve => setTimeout(() => {
console.log('done');
resolve("done");
}, 1000));
console.log('it finished');
}
test();
CLICK HERE to find out more related problems solutions.