caolan/highland

Calling `src.destroy()` in `src.map(...).stopOnError(ex)` errors with `Cannot write to stream after nil`.

Opened this issue · 0 comments

Calling src.destroy() in a stopOnError callback errors with Cannot write to stream after nil.

const nodeReadableStream = createNodeReadableStream();

const src = _(nodeReadableStream, () => () => nodeReadableStream.destroy());

src
  .map((msg) => {
    throw new Error('Failed to map msg');
  })
  .stopOnError((ex) => {
    console.log('Error:', ex);
    // Destroy the src so the underlying `nodeReadableStream` can clean up db connections etc.
    src.destroy(); // Causes 'Cannot write to stream after nil' error
  })
  .done(() => {
     console.log('DONE');
  });

Example:
https://runkit.com/embed/ntjjhyh6noz3