@@ -493,30 +493,30 @@ function onwrite(stream, er) {
493493 onwriteError ( stream , state , er , cb ) ;
494494 }
495495 } 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 &&
501497 ! state . bufferProcessing &&
502498 state . bufferedRequest ) {
503499 clearBuffer ( stream , state ) ;
504500 }
505501
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+ }
514515 } else {
515- state . afterWriteTickInfo = { count : 1 , cb, stream, state } ;
516- process . nextTick ( afterWriteTick , state . afterWriteTickInfo ) ;
516+ afterWrite ( stream , state , 1 , cb ) ;
517517 }
518518 } else {
519- afterWrite ( stream , state , 1 , cb ) ;
519+ state . pendingcb -- ;
520520 }
521521 }
522522}
0 commit comments