Skip to content

Commit

Permalink
fix: unhanded promise rejection in it-byte-stream (#130)
Browse files Browse the repository at this point in the history
If no consumer is listening for the next value, and the underlying
stream aborts, an unhandled promise rejection can occur.

Instead, add a `.catch` listener so the UPR doesn't occur, the
rejection will be processed next time a consumer tries to read a
value.
  • Loading branch information
achingbrain authored May 30, 2024
1 parent a20e5b5 commit 23bc557
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/it-byte-stream/src/pushable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class QueuelessPushable <T> implements Pushable<T> {
this.ended = true

if (err != null) {
// this can cause unhandled promise rejections if nothing is awaiting the
// next value so attach a dummy catch listener to the promise
this.haveNext.promise.catch(() => {})
this.haveNext.reject(err)
}

Expand Down

0 comments on commit 23bc557

Please sign in to comment.