Quantcast
Channel: User Ben Aston - Stack Overflow
Viewing all articles
Browse latest Browse all 56

Is it possible to wrap a setInterval in an async generator function?

$
0
0

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)})()

Viewing all articles
Browse latest Browse all 56

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>