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 2
2
3
3
exports . getMainThreadStdio = getMainThreadStdio ;
4
4
5
- function dummyDestroy ( err , cb ) { cb ( err ) ; }
5
+ function dummyDestroy ( err , cb ) {
6
+ // SyncWriteStream does not use the stream
7
+ // destroy mechanism for some legacy reason.
8
+ // TODO(mcollina): remove when
9
+ // https://github.com/nodejs/node/pull/26690 lands.
10
+ if ( typeof cb === 'function' ) {
11
+ cb ( err ) ;
12
+ }
13
+
14
+ // We need to emit 'close' anyway so that the closing
15
+ // of the stream is observable. We just make sure we
16
+ // are not going to do it twice.
17
+ // The 'close' event is needed so that finished and
18
+ // pipeline work correctly.
19
+ if ( ! this . _writableState . emitClose ) {
20
+ process . nextTick ( ( ) => {
21
+ this . emit ( 'close' ) ;
22
+ } ) ;
23
+ }
24
+ }
6
25
7
26
function getMainThreadStdio ( ) {
8
27
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