Created
June 27, 2019 05:48
-
-
Save kevinadi/df4f11ce6ac5b3cbd621600dcbbd0343 to your computer and use it in GitHub Desktop.
Promisifying and awaiting setTimeout
This file contains hidden or 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
function sleep(ms) { | |
return new Promise((resolve, reject) => { | |
console.log(`Sleeping for ${ms} ms...`) | |
setTimeout(() => resolve('Done sleeping'), ms) | |
}) | |
} | |
const run = async function() { | |
console.log('Run start') | |
const res = await sleep(2000) | |
console.log(res) | |
console.log('Run end') | |
} | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment