Created
April 14, 2019 20:59
-
-
Save mischah/dd05a2b2be4aabee0b05da37fb94d403 to your computer and use it in GitHub Desktop.
Promisified setTimeout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Promisified setTimeout | |
const delay = (duration = 0) => | |
new Promise(resolve => | |
setTimeout(() => { | |
resolve(); | |
}, duration) | |
); | |
// Usage | |
async function myFunction() { | |
console.log('Do something'); | |
await delay(); | |
console.log('Do something else'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment