Function onEnd

  • Notifies of the end of a successful iteration, for the immediately preceding operator, and provides a summary.

    It doesn't handle or affect any upstream errors, and should they occur, it may never reach the end, and thus never trigger the notification.

    The operator doesn't affect the iteration, unless the callback function throws an error.

    import {pipe, map, wait, onEnd, catchError} from 'iter-ops';

    const i = pipe(
    asyncIterable,
    map(a => myService.getValues(a)), // remap into requests-promises
    wait(), // resolve requests
    onEnd(s => {
    if(s.duration.average > 1000) {
    // took longer than 1s per value on average;
    throw new Error('Method getValues is too slow');
    }
    }),
    catchError((err, ctx) => {
    console.log(err?.message || err);
    throw err;
    })
    );

    Type Parameters

    • T

    Parameters

    Returns Operation<T, T>