Class Breaker<Input>

Error handler that breaks the execution of the pipeline on the first error. Compiling the data will return the data as is. This is similar to not having any error handling if you wish to do the error handling externally.

The Breaker handler is the default error handler for the ArrayStream and AsyncArrayStream classes.

const stream = new ArrayStream([1,2,3,4,5], new Breaker())
.map((x) => {
if (x === 3) {
throw new Error("test error");
}
return x;
})

try {
return [stream.collect(), null];
} catch (e) {
return [null, e];
}

Type Parameters

  • Input

Implements

Constructors

Methods

  • The Breaker error handler will return the data with no modifications, i.e.

    const stream = new ArrayStream([1,2,3,4,5], new Breaker()).collect();
    console.log(stream) // [1,2,3,4,5]

    Type Parameters

    • Data

    Parameters

    Returns Data

  • Rethrows an error with more context when an error occurs during an iteration, i.e.

    function* gen() {
    yield 1;
    throw new Error("test error");
    }

    const stream = new ArrayStream(gen, new Breaker()).collect();
    // throws: Error occurred at item at index 1 in iterator: test error

    Parameters

    • error: unknown
    • index: number

    Returns void

  • Rethrows an error with more context when an error occurs during an operation, i.e.

    const stream = new ArrayStream([1,2,3,4,5], new Breaker())
    .map((x) => {
    if (x === 3) {
    throw new Error("test error");
    }
    return x;
    })
    .collect()
    // throws: Error occurred while performing map on 3 at index 2 in iterator: test error

    Parameters

    • error: unknown
    • index: number
    • item: Input
    • op: string

    Returns void