MCPcopy Index your code
hub / github.com/nodejs/node / destroy

Function destroy

lib/internal/streams/destroy.js:49–88  ·  view source on GitHub ↗
(err, cb)

Source from the content-addressed store, hash-verified

47// Backwards compat. cb() is undocumented and unused in core but
48// unfortunately might be used by modules.
49function destroy(err, cb) {
50 const r = this._readableState;
51 const w = this._writableState;
52 // With duplex streams we use the writable side for state.
53 const s = w || r;
54
55 if (
56 (w && (w[kState] & kDestroyed) !== 0) ||
57 (r && (r[kState] & kDestroyed) !== 0)
58 ) {
59 if (typeof cb === 'function') {
60 cb();
61 }
62
63 return this;
64 }
65
66
67 // We set destroyed to true before firing error callbacks in order
68 // to make it re-entrance safe in case destroy() is called within callbacks
69 checkError(err, w, r);
70
71 if (w) {
72 w[kState] |= kDestroyed;
73 }
74 if (r) {
75 r[kState] |= kDestroyed;
76 }
77
78 // If still constructing then defer calling _destroy.
79 if ((s[kState] & kConstructed) === 0) {
80 this.once(kDestroy, function(er) {
81 _destroy(this, aggregateTwoErrors(er, err), cb);
82 });
83 } else {
84 _destroy(this, err, cb);
85 }
86
87 return this;
88}
89
90function _destroy(self, err, cb) {
91 let called = false;

Callers

nothing calls this directly

Calls 5

aggregateTwoErrorsFunction · 0.85
cbFunction · 0.70
checkErrorFunction · 0.70
_destroyFunction · 0.70
onceMethod · 0.45

Tested by

no test coverage detected