Calls callback whenever the async generator produces a value.
callback
When using asCallback, call it with await to let generator run its course before continuing:
asCallback
await
await asCallback(tick({ interval:1000, loops:5 }), x => { // Gets called 5 times, with 1000ms interval});console.log(`Hi`); // Prints after 5 seconds Copy
await asCallback(tick({ interval:1000, loops:5 }), x => { // Gets called 5 times, with 1000ms interval});console.log(`Hi`); // Prints after 5 seconds
Or if you skip the await, code continues and callback will still run:
asCallback(tick({ interval: 1000, loops: 5}), x => { // Gets called 5 times, with 1000ms interval});console.log(`Hi`); // Prints immediately Copy
asCallback(tick({ interval: 1000, loops: 5}), x => { // Gets called 5 times, with 1000ms interval});console.log(`Hi`); // Prints immediately
Optional
Calls
callback
whenever the async generator produces a value.When using
asCallback
, call it withawait
to let generator run its course before continuing:Or if you skip the
await
, code continues and callback will still run: