g33k57
7/9/2019 - 11:40 AM

Node.js Async/Await delay

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()