Without using the Streams API, is it possible to wrap a setInterval
in an async generator function, to simulate a never-ending stream?
I know how to do it using setTimeout
to supply the delay.
Using setTimeout
:
const wait = (delay = 500) => new Promise((resolve) => setTimeout(resolve, delay))
async function * countUp(count = 0) {
while(1) (await wait(), yield count++)
}
(async ()=> {
for await(let el of countUp())
console.log(el)
})()