4 ms·
hmm, it didn't occur to me to use a timer rather than hit the up arrow and enter. Now I have this to watch the time count up :) async function* seconds() {
by benatkin 3y ago
hmm, it didn't occur to me to use a timer rather than hit the up arrow and enter. Now I have this to watch the time count up :)
async function* seconds() {
while (true) {
const millis = new Date().valueOf()
const seconds = Math.ceil((millis + 10) / 1000)
const delay = (seconds * 1000) - millis
await new Promise(r => { setTimeout(() => r(), delay) })
yield seconds
}
}
for await (const s of seconds()) {
console.log(s)
}
- xeckr 3y ago>async generator >for await (const s of seconds()) I'd hate to be your code reviewer!