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

Function consume

deps/undici/undici.js:17307–17340  ·  view source on GitHub ↗
(stream, type)

Source from the content-addressed store, hash-verified

17305 }
17306 __name(isUnusable, "isUnusable");
17307 function consume(stream, type) {
17308 assert(!stream[kConsume]);
17309 return new Promise((resolve, reject) => {
17310 if (isUnusable(stream)) {
17311 const rState = stream._readableState;
17312 if (rState.destroyed && rState.closeEmitted === false) {
17313 stream.on("error", reject).on("close", () => {
17314 reject(new TypeError("unusable"));
17315 });
17316 } else {
17317 reject(rState.errored ?? new TypeError("unusable"));
17318 }
17319 } else {
17320 queueMicrotask(() => {
17321 stream[kConsume] = {
17322 type,
17323 stream,
17324 resolve,
17325 reject,
17326 length: 0,
17327 body: []
17328 };
17329 stream.on("error", function(err) {
17330 consumeFinish(this[kConsume], err);
17331 }).on("close", function() {
17332 if (this[kConsume].body !== null) {
17333 consumeFinish(this[kConsume], new RequestAbortedError());
17334 }
17335 });
17336 consumeStart(stream[kConsume]);
17337 });
17338 }
17339 });
17340 }
17341 __name(consume, "consume");
17342 function consumeStart(consume2) {
17343 if (consume2.body === null) {

Callers 5

textMethod · 0.70
jsonMethod · 0.70
blobMethod · 0.70
bytesMethod · 0.70
arrayBufferMethod · 0.70

Calls 7

queueMicrotaskFunction · 0.85
isUnusableFunction · 0.70
consumeFinishFunction · 0.70
consumeStartFunction · 0.70
assertFunction · 0.50
rejectFunction · 0.50
onMethod · 0.45

Tested by

no test coverage detected