Function consume

  • Exposes the source iterable to an external consumer, and emits a one-value iterable with that consumer.

    It is to simplify integration with external API that consumes iterables.

    import {pipeAsync, consume} from 'iter-ops';
    import {Readable} from 'stream';

    const i = pipeAsync(
    [1, 2, 3, 4, 5],
    consume(source => Readable.from(source))
    ); //=> AsyncIterableExt<Readable>

    const r = await i.first; //=> Readable stream

    The consumer callback can optionally return a Promise when inside asynchronous pipeline.

    Flag sync in the callback is true when the iterable is synchronous, and false when asynchronous.

    Type Parameters

    • T
    • R

    Parameters

    Returns Operation<T, R>