Skip to content

Instantly share code, notes, and snippets.

@kevinadi
Created June 27, 2019 05:48
Show Gist options
  • Save kevinadi/df4f11ce6ac5b3cbd621600dcbbd0343 to your computer and use it in GitHub Desktop.
Save kevinadi/df4f11ce6ac5b3cbd621600dcbbd0343 to your computer and use it in GitHub Desktop.
Promisifying and awaiting setTimeout
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