Function timing

  • Measures timings for each value, and provides a notification callback.

    It is mainly to help evaluate performance of asynchronous lengthy iterables, though it works synchronously also.

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

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

    const i = pipe(
    asyncIterable,
    map(a => myService.requestData(a)), // map into promises
    wait(), // resolve each promise
    timing(t => {
    if(t.duration > 3000) {
    // took over 3s to get the value, needs investigation;
    throw new Error(`Took too long to get value ${t.value} for index ${t.index}`);
    }
    }),
    catchError((err, ctx) => {
    console.log(err?.message || err);
    throw err;
    })
    );

    Type Parameters

    • T

    Parameters

    • cb: ((t) => void)

    Returns Operation<T, T>