Commit f4efb7f 1 parent 4a3525b commit f4efb7f Copy full SHA for f4efb7f
File tree 2 files changed +49
-3
lines changed
2 files changed +49
-3
lines changed Original file line number Diff line number Diff line change @@ -238,13 +238,14 @@ module.exports = function compose(...streams) {
238
238
ondrain = null ;
239
239
onfinish = null ;
240
240
241
+ if ( isNodeStream ( tail ) ) {
242
+ destroyer ( tail , err ) ;
243
+ }
244
+
241
245
if ( onclose === null ) {
242
246
callback ( err ) ;
243
247
} else {
244
248
onclose = callback ;
245
- if ( isNodeStream ( tail ) ) {
246
- destroyer ( tail , err ) ;
247
- }
248
249
}
249
250
} ;
250
251
Original file line number Diff line number Diff line change 4
4
5
5
const common = require ( '../common' ) ;
6
6
const {
7
+ Duplex,
7
8
Readable,
8
9
Transform,
9
10
Writable,
@@ -494,3 +495,47 @@ const assert = require('assert');
494
495
assert . deepStrictEqual ( await newStream . toArray ( ) , [ Buffer . from ( 'Steve RogersOn your left' ) ] ) ;
495
496
} ) ( ) . then ( common . mustCall ( ) ) ;
496
497
}
498
+
499
+ {
500
+ class DuplexProcess extends Duplex {
501
+ constructor ( options ) {
502
+ super ( { ...options , objectMode : true } ) ;
503
+ this . stuff = [ ] ;
504
+ }
505
+
506
+ _write ( message , _ , callback ) {
507
+ this . stuff . push ( message ) ;
508
+ callback ( ) ;
509
+ }
510
+
511
+ _destroy ( err , cb ) {
512
+ cb ( err ) ;
513
+ }
514
+
515
+ _read ( ) {
516
+ if ( this . stuff . length ) {
517
+ this . push ( this . stuff . shift ( ) ) ;
518
+ } else if ( this . writableEnded ) {
519
+ this . push ( null ) ;
520
+ } else {
521
+ this . _read ( ) ;
522
+ }
523
+ }
524
+ }
525
+
526
+ const pass = new PassThrough ( { objectMode : true } ) ;
527
+ const duplex = new DuplexProcess ( ) ;
528
+
529
+ const composed = compose (
530
+ pass ,
531
+ duplex
532
+ ) . on ( 'error' , ( ) => { } ) ;
533
+
534
+ composed . write ( 'hello' ) ;
535
+ composed . write ( 'world' ) ;
536
+ composed . end ( ) ;
537
+
538
+ composed . destroy ( new Error ( 'an unexpected error' ) ) ;
539
+ assert . strictEqual ( duplex . destroyed , true ) ;
540
+
541
+ }
You can’t perform that action at this time.
0 commit comments