sleep for 2 second javascript code example
Example 1: javascript async await for x seconds
function timeout(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function sleep(fn, ...args) {
await timeout(3000);
return fn(...args);
}
Example 2: wait javascript
wait(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}