• Asynchronously iterate over an event source

    Usage:

    for (const {item: event, next} of yield *each(mouseMove)) {
    console.log(event.clientX, event.clientY);
    yield next; // 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 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.

    Type Parameters

    • T

    Parameters

    Returns Yielding<Each<T>>