@@ -112,9 +112,13 @@ function _destroy(self, err, cb) {
112
112
}
113
113
114
114
if ( err ) {
115
- process . nextTick ( emitErrorCloseNT , self , err ) ;
115
+ queueMicrotask ( ( ) => {
116
+ emitErrorCloseNT ( self , err ) ;
117
+ } ) ;
116
118
} else {
117
- process . nextTick ( emitCloseNT , self ) ;
119
+ queueMicrotask ( ( ) => {
120
+ emitCloseNT ( self ) ;
121
+ } ) ;
118
122
}
119
123
}
120
124
try {
@@ -233,7 +237,9 @@ function errorOrDestroy(stream, err, sync) {
233
237
r . errored = err ;
234
238
}
235
239
if ( sync ) {
236
- process . nextTick ( emitErrorNT , stream , err ) ;
240
+ queueMicrotask ( ( ) => {
241
+ emitErrorNT ( stream , err ) ;
242
+ } ) ;
237
243
} else {
238
244
emitErrorNT ( stream , err ) ;
239
245
}
@@ -262,7 +268,9 @@ function construct(stream, cb) {
262
268
return ;
263
269
}
264
270
265
- process . nextTick ( constructNT , stream ) ;
271
+ queueMicrotask ( ( ) => {
272
+ constructNT ( stream ) ;
273
+ } ) ;
266
274
}
267
275
268
276
function constructNT ( stream ) {
@@ -291,16 +299,22 @@ function constructNT(stream) {
291
299
} else if ( err ) {
292
300
errorOrDestroy ( stream , err , true ) ;
293
301
} else {
294
- process . nextTick ( emitConstructNT , stream ) ;
302
+ queueMicrotask ( ( ) => {
303
+ emitConstructNT ( stream ) ;
304
+ } ) ;
295
305
}
296
306
}
297
307
298
308
try {
299
309
stream . _construct ( ( err ) => {
300
- process . nextTick ( onConstruct , err ) ;
310
+ queueMicrotask ( ( ) => {
311
+ onConstruct ( err ) ;
312
+ } ) ;
301
313
} ) ;
302
314
} catch ( err ) {
303
- process . nextTick ( onConstruct , err ) ;
315
+ queueMicrotask ( ( ) => {
316
+ onConstruct ( err ) ;
317
+ } ) ;
304
318
}
305
319
}
306
320
@@ -318,11 +332,14 @@ function emitCloseLegacy(stream) {
318
332
319
333
function emitErrorCloseLegacy ( stream , err ) {
320
334
stream . emit ( 'error' , err ) ;
321
- process . nextTick ( emitCloseLegacy , stream ) ;
335
+ queueMicrotask ( ( ) => {
336
+ emitCloseLegacy ( stream ) ;
337
+ } ) ;
322
338
}
323
339
324
340
// Normalize destroy for legacy.
325
341
function destroyer ( stream , err ) {
342
+ process . _rawDebug ( "### 0" )
326
343
if ( ! stream || isDestroyed ( stream ) ) {
327
344
return ;
328
345
}
@@ -345,9 +362,13 @@ function destroyer(stream, err) {
345
362
// TODO: Don't lose err?
346
363
stream . close ( ) ;
347
364
} else if ( err ) {
348
- process . nextTick ( emitErrorCloseLegacy , stream , err ) ;
365
+ queueMicrotask ( ( ) => {
366
+ emitErrorCloseLegacy ( stream , err ) ;
367
+ } ) ;
349
368
} else {
350
- process . nextTick ( emitCloseLegacy , stream ) ;
369
+ queueMicrotask ( ( ) => {
370
+ emitCloseLegacy ( stream ) ;
371
+ } ) ;
351
372
}
352
373
353
374
if ( ! stream . destroyed ) {
0 commit comments