Skip to content

Instantly share code, notes, and snippets.

@yurynix
Created May 5, 2020 07:56
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 yurynix/c7d5d182f71bc40a8b9ca542917bcff1 to your computer and use it in GitHub Desktop.
Save yurynix/c7d5d182f71bc40a8b9ca542917bcff1 to your computer and use it in GitHub Desktop.
Sleep 2 seconds
const { promisify } = require('util');
const sleep = promisify(setTimeout);
(async function main() {
await sleep(2 * 1000);
console.log("I'm printed after 2 seconds.");
}());
// 1. Why we might expect that code not to work?
// 2. Why it actually _does_ work?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment