Created
December 19, 2019 02:37
-
-
Save tejas-hosamani/b495f0912865cfca43cae59be0611a3d to your computer and use it in GitHub Desktop.
To test if something is Async or not
This file contains hidden or 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
// 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