Skip to content

Instantly share code, notes, and snippets.

@tejas-hosamani
Created December 19, 2019 02:37
Show Gist options
  • Save tejas-hosamani/b495f0912865cfca43cae59be0611a3d to your computer and use it in GitHub Desktop.
Save tejas-hosamani/b495f0912865cfca43cae59be0611a3d to your computer and use it in GitHub Desktop.
To test if something is Async or not
// CREDIT: https://stackoverflow.com/questions/33289726/combination-of-async-function-await-settimeout
//Since Node 7.6, you can combine the functions promisify function from the utils module with setTimeout() .
//Node.js
const sleep = require('util').promisify(setTimeout)
//Javascript
const sleep = m => new Promise(r => setTimeout(r, m))
//Usage
(async () => {
console.time("Slept for")
await sleep(3000)
console.timeEnd("Slept for")
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment