| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e3e2f22 commit 783322f
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -459,6 +459,7 @@ function newReadableStreamFromStreamReadable(streamReadable, options = kEmptyObj | |||
| 459 | 459 | const strategy = evaluateStrategyOrFallback(options?.strategy); | |
| 460 | 460 | ||
| 461 | 461 | let controller; | |
| 462 | + let wasCanceled = false; | ||
| 462 | 463 | ||
| 463 | 464 | function onData(chunk) { | |
| 464 | 465 | // Copy the Buffer to detach it from the pool. | |
@@ -480,6 +481,10 @@ function newReadableStreamFromStreamReadable(streamReadable, options = kEmptyObj | |||
| 480 | 481 | streamReadable.on('error', () => {}); | |
| 481 | 482 | if (error) | |
| 482 | 483 | return controller.error(error); | |
| 484 | + // Was already canceled | ||
| 485 | + if (wasCanceled) { | ||
| 486 | + return; | ||
| 487 | + } | ||
| 483 | 488 | controller.close(); | |
| 484 | 489 | }); | |
| 485 | 490 | ||
@@ -491,6 +496,7 @@ function newReadableStreamFromStreamReadable(streamReadable, options = kEmptyObj | |||
| 491 | 496 | pull() { streamReadable.resume(); }, | |
| 492 | 497 | ||
| 493 | 498 | cancel(reason) { | |
| 499 | + wasCanceled = true; | ||
| 494 | 500 | destroy(streamReadable, reason); | |
| 495 | 501 | }, | |
| 496 | 502 | }, strategy); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,15 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + require('../common'); | ||
| 3 | + const { Readable } = require('stream'); | ||
| 4 | + | ||
| 5 | + { | ||
| 6 | + const r = Readable.from(['data']); | ||
| 7 | + | ||
| 8 | + const wrapper = Readable.fromWeb(Readable.toWeb(r)); | ||
| 9 | + | ||
| 10 | + wrapper.on('data', () => { | ||
| 11 | + // Destroying wrapper while emitting data should not cause uncaught | ||
| 12 | + // exceptions | ||
| 13 | + wrapper.destroy(); | ||
| 14 | + }); | ||
| 15 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,12 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + require('../common'); | ||
| 3 | + const { Readable } = require('stream'); | ||
| 4 | + | ||
| 5 | + { | ||
| 6 | + const r = Readable.from([]); | ||
| 7 | + // Cancelling reader while closing should not cause uncaught exceptions | ||
| 8 | + r.on('close', () => reader.cancel()); | ||
| 9 | + | ||
| 10 | + const reader = Readable.toWeb(r).getReader(); | ||
| 11 | + reader.read(); | ||
| 12 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments