caolan / caolan/highland

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

Open
#702 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
3.4k
Forks
145
PR merge metrics
No merged PRs in 30d

Description

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

```js
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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.