set timeout promise javascript await code example
Example 1: await setTimeout
function timeout(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function sleep(fn, ...args) {
await timeout(3000);
return fn(...args);
}
Example 2: await set timeout
await new Promise(resolve => setTimeout(resolve, 1000));