X Tutup
The Wayback Machine - https://web.archive.org/web/20220420045102/https://github.com/nodejs/node/commit/e0d3b758a0
Skip to content
Permalink
Browse files
stream: improve Writable.destroy performance
Avoid nextTick if there are no pending callbacks.

PR-URL: #35067
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ricky Zhou <0x19951125@gmail.com>
  • Loading branch information
ronag authored and Trott committed Sep 7, 2020
1 parent e06037a commit e0d3b758a016bd926e890e5acc71d321faf9bc09
Showing with 9 additions and 1 deletion.
  1. +9 −1 lib/_stream_writable.js
@@ -45,6 +45,7 @@ const {
getHighWaterMark,
getDefaultHighWaterMark
} = require('internal/streams/state');
const assert = require('internal/assert');
const {
ERR_INVALID_ARG_TYPE,
ERR_METHOD_NOT_IMPLEMENTED,
@@ -826,9 +827,16 @@ ObjectDefineProperties(Writable.prototype, {
const destroy = destroyImpl.destroy;
Writable.prototype.destroy = function(err, cb) {
const state = this._writableState;
if (!state.destroyed) {

// Invoke pending callbacks.
if (
state.bufferedIndex < state.buffered.length ||
state[kOnFinished].length
) {
assert(!state.destroyed);
process.nextTick(errorBuffer, state);
}

destroy.call(this, err, cb);
return this;
};

0 comments on commit e0d3b75

Please sign in to comment.
X Tutup