write blocking sleep javascript code example
Example 1: wait javascript
wait(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
Example 2: javascript sleep settimeout
setTimeout(() => { console.log("World!"); }, 2000);
wait(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
setTimeout(() => { console.log("World!"); }, 2000);