by xeckr · 3y ago · 0 comments
setInterval(() => console.log(Date.now()), 1);
to watch the transition. Happy 1.7B seconds since Jan 1 1970! 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)
}>for await (const s of seconds())
I'd hate to be your code reviewer!