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

Function trackWritableLifecycle

deps/undici/undici.js:17731–17760  ·  view source on GitHub ↗
(stream2, callback)

Source from the content-addressed store, hash-verified

17729 }
17730 __name(createPrematureCloseError, "createPrematureCloseError");
17731 function trackWritableLifecycle(stream2, callback) {
17732 let done = false;
17733 const cleanup = /* @__PURE__ */ __name(() => {
17734 stream2.removeListener("close", onClose);
17735 stream2.removeListener("error", onError);
17736 stream2.removeListener("finish", onFinish);
17737 }, "cleanup");
17738 const finish = /* @__PURE__ */ __name((err, fromErrorEvent = false) => {
17739 if (done) {
17740 return;
17741 }
17742 done = true;
17743 cleanup();
17744 callback(err, fromErrorEvent);
17745 }, "finish");
17746 const onClose = /* @__PURE__ */ __name(() => {
17747 const err = getWritableError(stream2);
17748 finish(err ?? (!stream2.writableFinished ? createPrematureCloseError() : void 0));
17749 }, "onClose");
17750 const onError = /* @__PURE__ */ __name((err) => finish(err, true), "onError");
17751 const onFinish = /* @__PURE__ */ __name(() => finish(), "onFinish");
17752 stream2.on("close", onClose);
17753 stream2.on("error", onError);
17754 stream2.on("finish", onFinish);
17755 if (stream2.closed) {
17756 process.nextTick(onClose);
17757 } else if (stream2.writableFinished) {
17758 process.nextTick(onFinish);
17759 }
17760 }
17761 __name(trackWritableLifecycle, "trackWritableLifecycle");
17762 var StreamHandler = class extends AsyncResource {
17763 static {

Callers 1

onResponseStartMethod · 0.70

Calls 8

__nameFunction · 0.85
getWritableErrorFunction · 0.70
cleanupFunction · 0.50
callbackFunction · 0.50
finishFunction · 0.50
removeListenerMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected