(err, cb)
| 47 | // Backwards compat. cb() is undocumented and unused in core but |
| 48 | // unfortunately might be used by modules. |
| 49 | function 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 | |
| 90 | function _destroy(self, err, cb) { |
| 91 | let called = false; |
nothing calls this directly
no test coverage detected