MCPcopy
hub / github.com/di-sukharev/opencommit / writeIterable

Function writeIterable

out/cli.cjs:55221–55278  ·  view source on GitHub ↗
({ h2stream, body, client, request: request3, socket, contentLength, header, expectsPayload })

Source from the content-addressed store, hash-verified

55219 if (!expectsPayload) {
55220 socket[kReset] = true;
55221 }
55222 resume2(client);
55223 } catch (err) {
55224 util4.destroy(isH2 ? h2stream : socket, err);
55225 }
55226 }
55227 async function writeIterable({ h2stream, body, client, request: request3, socket, contentLength, header, expectsPayload }) {
55228 assert2(contentLength !== 0 || client[kRunning] === 0, "iterator body cannot be pipelined");
55229 let callback = null;
55230 function onDrain() {
55231 if (callback) {
55232 const cb = callback;
55233 callback = null;
55234 cb();
55235 }
55236 }
55237 const waitForDrain = () => new Promise((resolve, reject) => {
55238 assert2(callback === null);
55239 if (socket[kError]) {
55240 reject(socket[kError]);
55241 } else {
55242 callback = resolve;
55243 }
55244 });
55245 if (client[kHTTPConnVersion] === "h2") {
55246 h2stream.on("close", onDrain).on("drain", onDrain);
55247 try {
55248 for await (const chunk of body) {
55249 if (socket[kError]) {
55250 throw socket[kError];
55251 }
55252 const res = h2stream.write(chunk);
55253 request3.onBodySent(chunk);
55254 if (!res) {
55255 await waitForDrain();
55256 }
55257 }
55258 } catch (err) {
55259 h2stream.destroy(err);
55260 } finally {
55261 request3.onRequestSent();
55262 h2stream.end();
55263 h2stream.off("close", onDrain).off("drain", onDrain);
55264 }
55265 return;
55266 }
55267 socket.on("close", onDrain).on("drain", onDrain);
55268 const writer = new AsyncWriter({ socket, request: request3, contentLength, client, expectsPayload, header });
55269 try {
55270 for await (const chunk of body) {
55271 if (socket[kError]) {
55272 throw socket[kError];
55273 }
55274 if (!writer.write(chunk)) {
55275 await waitForDrain();
55276 }
55277 }
55278 writer.end();

Callers 2

writeFunction · 0.85
writeBodyH2Function · 0.85

Calls 8

waitForDrainFunction · 0.85
endMethod · 0.80
onMethod · 0.45
writeMethod · 0.45
onBodySentMethod · 0.45
destroyMethod · 0.45
onRequestSentMethod · 0.45
offMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…