Skip to content

Instantly share code, notes, and snippets.

@teebu
Forked from daliborgogic/delay.js
Created July 6, 2018 05:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teebu/a26eb36e96380a1891efb3edac7cc7d2 to your computer and use it in GitHub Desktop.
Save teebu/a26eb36e96380a1891efb3edac7cc7d2 to your computer and use it in GitHub Desktop.
Node.js Async/Await delay
'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