vitaly-t / iter-ops

Basic operations on iterables
https://vitaly-t.github.io/iter-ops
MIT License
136 stars 5 forks source link

Operator timeout should forward callback errors #220

Closed vitaly-t closed 1 year ago

vitaly-t commented 1 year ago

Currently, if you throw an error while handling callback of operator timeout, it is not handled. It should be caught and passed on down the chain.

Why it matters: you may want to handle a callback, and turn it into an error that will be handled in a generic way, via catchError.

It can be considered both a bug (more likely) and an enhancement.

NOTE: This issue primarily affects the async version of the operator.

vitaly-t commented 1 year ago

The fix was implemented in v3.0.5, which makes the following possible:

const i = pipeAsync([1, 2, 3], delay(10), timeout(1, () => {
    throw new Error('timeout');
}))
.catch(err => {
    console.log(err); //=> Error: "timeout"
});

i.e. if you throw an error inside timeout callback, it previously would not be handled correctly, but now it is.