Created
October 13, 2021 04:01
-
-
Save alii/3c661677811c8e12d7b30910fd77eb95 to your computer and use it in GitHub Desktop.
Experimenting with Node `timers/promises`
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
import { setInterval } from "timers/promises"; | |
const createCounter = (initial = 0) => { | |
let value = initial; | |
return () => ++value; | |
}; | |
const start = Date.now(); | |
for await (const incr of setInterval(1000, createCounter())) { | |
const i = incr(); | |
console.log(i, Date.now() - start); | |
if (i >= 10) { | |
break; | |
} | |
} | |
console.log("Done!"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment