Skip to content

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

@richardscarrott

Description

@richardscarrott

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions