@@ -248,7 +248,7 @@ class Client extends EventEmitter {
248248 } else if ( util . isStream ( request . body ) ) {
249249 // Wait a tick in case stream is ended in the same tick.
250250 this [ kResuming ] = 1
251- process . nextTick ( resume , this )
251+ util . queueMicrotask ( ( ) => resume ( this ) )
252252 } else {
253253 resume ( this , true )
254254 }
@@ -275,7 +275,9 @@ class Client extends EventEmitter {
275275 }
276276
277277 if ( this [ kDestroyed ] ) {
278- process . nextTick ( callback , new ClientDestroyedError ( ) , null )
278+ util . queueMicrotask ( ( ) => {
279+ callback ( new ClientDestroyedError ( ) , null )
280+ } )
279281 return
280282 }
281283
@@ -310,7 +312,7 @@ class Client extends EventEmitter {
310312 if ( this [ kOnDestroyed ] ) {
311313 this [ kOnDestroyed ] . push ( callback )
312314 } else {
313- process . nextTick ( callback , null , null )
315+ util . queueMicrotask ( ( ) => callback ( null , null ) )
314316 }
315317 return
316318 }
@@ -336,7 +338,7 @@ class Client extends EventEmitter {
336338 }
337339
338340 if ( ! this [ kSocket ] ) {
339- process . nextTick ( onDestroyed )
341+ util . queueMicrotask ( ( ) => onDestroyed ( ) )
340342 } else {
341343 util . destroy ( this [ kSocket ] . on ( 'close' , onDestroyed ) , err )
342344 }
@@ -967,7 +969,7 @@ function _resume (client, sync) {
967969 } else if ( client [ kNeedDrain ] === 2 ) {
968970 if ( sync ) {
969971 client [ kNeedDrain ] = 1
970- process . nextTick ( emitDrain , client )
972+ util . queueMicrotask ( ( ) => emitDrain ( client ) )
971973 } else {
972974 emitDrain ( client )
973975 }
0 commit comments