MCPcopy Create free account
hub / github.com/nodejs/node / destroy

Function destroy

deps/undici/src/lib/core/util.js:362–383  ·  view source on GitHub ↗

* @param {import ('stream').Stream} stream * @param {Error} [err] * @returns {void}

(stream, err)

Source from the content-addressed store, hash-verified

360 * @returns {void}
361 */
362function destroy (stream, err) {
363 if (stream == null || !isStream(stream) || isDestroyed(stream)) {
364 return
365 }
366
367 if (typeof stream.destroy === 'function') {
368 if (Object.getPrototypeOf(stream).constructor === IncomingMessage) {
369 // See: https://github.com/nodejs/node/pull/38505/files
370 stream.socket = null
371 }
372
373 stream.destroy(err)
374 } else if (err) {
375 queueMicrotask(() => {
376 stream.emit('error', err)
377 })
378 }
379
380 if (stream.destroyed !== true) {
381 stream[kDestroyed] = true
382 }
383}
384
385const KEEPALIVE_TIMEOUT_EXPR = /timeout=(\d+)/
386/**

Callers 2

onConnectTimeoutFunction · 0.70
constructorMethod · 0.70

Calls 5

queueMicrotaskFunction · 0.85
isStreamFunction · 0.70
isDestroyedFunction · 0.70
destroyMethod · 0.45
emitMethod · 0.45

Tested by

no test coverage detected