| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 62bf03b commit f408536
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -424,6 +424,7 @@ function newReadableStreamFromStreamReadable(streamReadable, options = kEmptyObj | |||
| 424 | 424 | const strategy = evaluateStrategyOrFallback(options?.strategy); | |
| 425 | 425 | ||
| 426 | 426 | let controller; | |
| 427 | + let wasCanceled = false; | ||
| 427 | 428 | ||
| 428 | 429 | function onData(chunk) { | |
| 429 | 430 | // Copy the Buffer to detach it from the pool. | |
@@ -448,6 +449,10 @@ function newReadableStreamFromStreamReadable(streamReadable, options = kEmptyObj | |||
| 448 | 449 | streamReadable.on('error', () => {}); | |
| 449 | 450 | if (error) | |
| 450 | 451 | return controller.error(error); | |
| 452 | + // Was already canceled | ||
| 453 | + if (wasCanceled) { | ||
| 454 | + return; | ||
| 455 | + } | ||
| 451 | 456 | controller.close(); | |
| 452 | 457 | }); | |
| 453 | 458 | ||
@@ -459,6 +464,7 @@ function newReadableStreamFromStreamReadable(streamReadable, options = kEmptyObj | |||
| 459 | 464 | pull() { streamReadable.resume(); }, | |
| 460 | 465 | ||
| 461 | 466 | cancel(reason) { | |
| 467 | + wasCanceled = true; | ||
| 462 | 468 | destroy(streamReadable, reason); | |
| 463 | 469 | }, | |
| 464 | 470 | }, 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