File tree 2 files changed +51
-1
lines changed
2 files changed +51
-1
lines changed Original file line number Diff line number Diff line change 8
8
exports . setupProcessStdio = setupProcessStdio ;
9
9
exports . getMainThreadStdio = getMainThreadStdio ;
10
10
11
- function dummyDestroy ( err , cb ) { cb ( err ) ; }
11
+ function dummyDestroy ( err , cb ) {
12
+ // SyncWriteStream does not use the stream
13
+ // destroy mechanism for some legacy reason.
14
+ // TODO(mcollina): remove when
15
+ // https://github.com/nodejs/node/pull/26690 lands.
16
+ if ( typeof cb === 'function' ) {
17
+ cb ( err ) ;
18
+ }
19
+
20
+ // We need to emit 'close' anyway so that the closing
21
+ // of the stream is observable. We just make sure we
22
+ // are not going to do it twice.
23
+ // The 'close' event is needed so that finished and
24
+ // pipeline work correctly.
25
+ if ( ! this . _writableState . emitClose ) {
26
+ process . nextTick ( ( ) => {
27
+ this . emit ( 'close' ) ;
28
+ } ) ;
29
+ }
30
+ }
12
31
13
32
function getMainThreadStdio ( ) {
14
33
var stdin ;
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const common = require ( '../common' ) ;
4
+ const { Transform, Readable, pipeline } = require ( 'stream' ) ;
5
+ const assert = require ( 'assert' ) ;
6
+
7
+ const reader = new Readable ( {
8
+ read ( size ) { this . push ( 'foo' ) ; }
9
+ } ) ;
10
+
11
+ let count = 0 ;
12
+
13
+ const err = new Error ( 'this-error-gets-hidden' ) ;
14
+
15
+ const transform = new Transform ( {
16
+ transform ( chunk , enc , cb ) {
17
+ if ( count ++ >= 5 )
18
+ this . emit ( 'error' , err ) ;
19
+ else
20
+ cb ( null , count . toString ( ) + '\n' ) ;
21
+ }
22
+ } ) ;
23
+
24
+ pipeline (
25
+ reader ,
26
+ transform ,
27
+ process . stdout ,
28
+ common . mustCall ( ( e ) => {
29
+ assert . strictEqual ( e , err ) ;
30
+ } )
31
+ ) ;
You can’t perform that action at this time.
0 commit comments