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

Function pumpToNode

lib/internal/streams/pipeline.js:95–151  ·  view source on GitHub ↗
(iterable, writable, finish, { end })

Source from the content-addressed store, hash-verified

93}
94
95async function pumpToNode(iterable, writable, finish, { end }) {
96 let error;
97 let onresolve = null;
98
99 const resume = (err) => {
100 if (err) {
101 error = err;
102 }
103
104 if (onresolve) {
105 const callback = onresolve;
106 onresolve = null;
107 callback();
108 }
109 };
110
111 const wait = () => new Promise((resolve, reject) => {
112 if (error) {
113 reject(error);
114 } else {
115 onresolve = () => {
116 if (error) {
117 reject(error);
118 } else {
119 resolve();
120 }
121 };
122 }
123 });
124
125 writable.on('drain', resume);
126 const cleanup = eos(writable, { readable: false }, resume);
127
128 try {
129 if (writable.writableNeedDrain) {
130 await wait();
131 }
132
133 for await (const chunk of iterable) {
134 if (!writable.write(chunk)) {
135 await wait();
136 }
137 }
138
139 if (end) {
140 writable.end();
141 await wait();
142 }
143
144 finish();
145 } catch (err) {
146 finish(error !== err ? aggregateTwoErrors(error, err) : err);
147 } finally {
148 cleanup();
149 writable.off('drain', resume);
150 }
151}
152

Callers 1

pipelineImplFunction · 0.85

Calls 9

eosFunction · 0.85
aggregateTwoErrorsFunction · 0.85
waitFunction · 0.70
finishFunction · 0.70
cleanupFunction · 0.70
onMethod · 0.45
writeMethod · 0.45
endMethod · 0.45
offMethod · 0.45

Tested by

no test coverage detected