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

Function writeBatch

lib/internal/streams/iter/pull.js:1033–1063  ·  view source on GitHub ↗
(batch)

Source from the content-addressed store, hash-verified

1031 // Returns undefined on sync success, or a Promise when async fallback
1032 // is required. Callers must check: const p = writeBatch(b); if (p) await p;
1033 function writeBatch(batch) {
1034 if (hasWritev && batch.length > 1) {
1035 if (!hasWritevSync || !writer.writevSync(batch)) {
1036 const opts = signal ? { __proto__: null, signal } : undefined;
1037 const writevResult = writer.writev(batch, opts);
1038 if (writevResult === undefined) {
1039 for (let i = 0; i < batch.length; i++) {
1040 totalBytes += TypedArrayPrototypeGetByteLength(batch[i]);
1041 }
1042 return;
1043 }
1044 return PromisePrototypeThen(PromiseResolve(writevResult), () => {
1045 for (let i = 0; i < batch.length; i++) {
1046 totalBytes += TypedArrayPrototypeGetByteLength(batch[i]);
1047 }
1048 });
1049 }
1050 for (let i = 0; i < batch.length; i++) {
1051 totalBytes += TypedArrayPrototypeGetByteLength(batch[i]);
1052 }
1053 return;
1054 }
1055 for (let i = 0; i < batch.length; i++) {
1056 const chunk = batch[i];
1057 if (!hasWriteSync || !writer.writeSync(chunk)) {
1058 // Sync path failed at index i - fall back to async for the rest.
1059 return writeBatchAsyncFallback(batch, i);
1060 }
1061 totalBytes += TypedArrayPrototypeGetByteLength(chunk);
1062 }
1063 }
1064
1065 try {
1066 if (useSyncIterableFastPath) {

Callers 1

pipeToFunction · 0.85

Calls 4

writeBatchAsyncFallbackFunction · 0.85
writevSyncMethod · 0.45
writevMethod · 0.45
writeSyncMethod · 0.45

Tested by

no test coverage detected