@@ -493,30 +493,30 @@ function onwrite(stream, er) {
493
493
onwriteError ( stream , state , er , cb ) ;
494
494
}
495
495
} else {
496
- // Check if we're actually ready to finish, but don't emit yet
497
- var finished = needFinish ( state ) || stream . destroyed ;
498
-
499
- if ( ! finished &&
500
- ! state . corked &&
496
+ if ( ! state . corked &&
501
497
! state . bufferProcessing &&
502
498
state . bufferedRequest ) {
503
499
clearBuffer ( stream , state ) ;
504
500
}
505
501
506
- if ( sync ) {
507
- // It is a common case that the callback passed to .write() is always
508
- // the same. In that case, we do not schedule a new nextTick(), but rather
509
- // just increase a counter, to improve performance and avoid memory
510
- // allocations.
511
- if ( state . afterWriteTickInfo !== null &&
512
- state . afterWriteTickInfo . cb === cb ) {
513
- state . afterWriteTickInfo . count ++ ;
502
+ if ( state . ending || state . needDrain || cb !== nop ) {
503
+ if ( sync ) {
504
+ // It is a common case that the callback passed to .write() is always
505
+ // the same. In that case, we do not schedule a new nextTick(), but
506
+ // rather just increase a counter, to improve performance and avoid
507
+ // memory allocations.
508
+ if ( state . afterWriteTickInfo !== null &&
509
+ state . afterWriteTickInfo . cb === cb ) {
510
+ state . afterWriteTickInfo . count ++ ;
511
+ } else {
512
+ state . afterWriteTickInfo = { count : 1 , cb, stream, state } ;
513
+ process . nextTick ( afterWriteTick , state . afterWriteTickInfo ) ;
514
+ }
514
515
} else {
515
- state . afterWriteTickInfo = { count : 1 , cb, stream, state } ;
516
- process . nextTick ( afterWriteTick , state . afterWriteTickInfo ) ;
516
+ afterWrite ( stream , state , 1 , cb ) ;
517
517
}
518
518
} else {
519
- afterWrite ( stream , state , 1 , cb ) ;
519
+ state . pendingcb -- ;
520
520
}
521
521
}
522
522
}
0 commit comments