summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/readable-stream/lib/internal/streams/destroy.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/readable-stream/lib/internal/streams/destroy.js')
-rw-r--r--deps/npm/node_modules/readable-stream/lib/internal/streams/destroy.js39
1 files changed, 25 insertions, 14 deletions
diff --git a/deps/npm/node_modules/readable-stream/lib/internal/streams/destroy.js b/deps/npm/node_modules/readable-stream/lib/internal/streams/destroy.js
index 5a0a0d88ce..63ae49928d 100644
--- a/deps/npm/node_modules/readable-stream/lib/internal/streams/destroy.js
+++ b/deps/npm/node_modules/readable-stream/lib/internal/streams/destroy.js
@@ -1,11 +1,5 @@
-'use strict';
+'use strict'; // undocumented cb() API, needed for core, not for public API
-/*<replacement>*/
-
-var pna = require('process-nextick-args');
-/*</replacement>*/
-
-// undocumented cb() API, needed for core, not for public API
function destroy(err, cb) {
var _this = this;
@@ -16,37 +10,52 @@ function destroy(err, cb) {
if (cb) {
cb(err);
} else if (err && (!this._writableState || !this._writableState.errorEmitted)) {
- pna.nextTick(emitErrorNT, this, err);
+ process.nextTick(emitErrorNT, this, err);
}
- return this;
- }
- // we set destroyed to true before firing error callbacks in order
+ return this;
+ } // we set destroyed to true before firing error callbacks in order
// to make it re-entrance safe in case destroy() is called within callbacks
+
if (this._readableState) {
this._readableState.destroyed = true;
- }
+ } // if this is a duplex stream mark the writable part as destroyed as well
+
- // if this is a duplex stream mark the writable part as destroyed as well
if (this._writableState) {
this._writableState.destroyed = true;
}
this._destroy(err || null, function (err) {
if (!cb && err) {
- pna.nextTick(emitErrorNT, _this, err);
+ process.nextTick(emitErrorAndCloseNT, _this, err);
+
if (_this._writableState) {
_this._writableState.errorEmitted = true;
}
} else if (cb) {
+ process.nextTick(emitCloseNT, _this);
cb(err);
+ } else {
+ process.nextTick(emitCloseNT, _this);
}
});
return this;
}
+function emitErrorAndCloseNT(self, err) {
+ emitErrorNT(self, err);
+ emitCloseNT(self);
+}
+
+function emitCloseNT(self) {
+ if (self._writableState && !self._writableState.emitClose) return;
+ if (self._readableState && !self._readableState.emitClose) return;
+ self.emit('close');
+}
+
function undestroy() {
if (this._readableState) {
this._readableState.destroyed = false;
@@ -59,6 +68,8 @@ function undestroy() {
this._writableState.destroyed = false;
this._writableState.ended = false;
this._writableState.ending = false;
+ this._writableState.finalCalled = false;
+ this._writableState.prefinished = false;
this._writableState.finished = false;
this._writableState.errorEmitted = false;
}