for (const {item: event, next} ofyield*each(mouseMove)) { console.log(event.clientX, event.clientY); yieldnext; // required exactly once per iteration, even/w continue! }
each(eventSource) yield-returns an iterator of {item, next} pairs. The
item is the data supplied by the event source, and next is a
Suspend<void> that advances the iterator to the next item. It
must be yielded exactly once per loop iteration. If you use continue to
shortcut the loop body, you must yield nextbefore doing so.
The for-loop will end if the source ends, errors, or is canceled. The source
is paused while the loop body is running, and resumed when the yield next
happens. If events arrive anyway (e.g. because the source doesn't support
pausing), they will be ignored unless you pipe the source through the
slack() operator to provide a buffer. If the for-loop is exited
early for any reason (or the iterator's .return() is called), the source is
unsubscribed and the iteration ended.
Asynchronously iterate over an event source
Usage:
each(eventSource) yield-returns an iterator of
{item, next}
pairs. The item is the data supplied by the event source, andnext
is a Suspend<void> that advances the iterator to the next item. It must be yielded exactly once per loop iteration. If you usecontinue
to shortcut the loop body, you mustyield next
before doing so.The for-loop will end if the source ends, errors, or is canceled. The source is paused while the loop body is running, and resumed when the
yield next
happens. If events arrive anyway (e.g. because the source doesn't support pausing), they will be ignored unless you pipe the source through the slack() operator to provide a buffer. If the for-loop is exited early for any reason (or the iterator's.return()
is called), the source is unsubscribed and the iteration ended.