-
-
Save Harshakvarma/0ce74345095d43d1dc8f3802a6e82d92 to your computer and use it in GitHub Desktop.
Node.js Async/Await delay
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
'use strict' | |
const timeout = ms => new Promise(res => setTimeout(res, ms)) | |
function convinceMe (convince) { | |
let unixTime = Math.round(+new Date() / 1000) | |
console.log(`Delay ${convince} at ${unixTime}`) | |
} | |
async function delay () { | |
convinceMe('started') | |
await timeout(5000) | |
convinceMe('finished') | |
} | |
delay() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment