Skip to content

Instantly share code, notes, and snippets.

@LinZap
Created June 9, 2019 12:19
Show Gist options
  • Save LinZap/bb2826367aa19398f8ce070d2571ad27 to your computer and use it in GitHub Desktop.
Save LinZap/bb2826367aa19398f8ce070d2571ad27 to your computer and use it in GitHub Desktop.
Node.js - HK6
function delay(ms) {
return new Promise(resolve => setTimeout(() => {
console.log(new Date())
resolve()
}, ms))
}
let p = delay(1000);
for (let i = 0; i < 4; i++) {
p = p.then(() => delay(1000))
}
2019-06-09T12:16:24.854Z
2019-06-09T12:16:25.864Z
2019-06-09T12:16:26.866Z
2019-06-09T12:16:27.867Z
2019-06-09T12:16:28.868Z
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment