MCPcopy Index your code
hub / github.com/nodejs/node / #createPendingWrite

Method #createPendingWrite

lib/internal/streams/iter/push.js:241–268  ·  view source on GitHub ↗

* Create a pending write promise, optionally racing against a signal. * If the signal fires, the entry is removed from pendingWrites and the * promise rejects. Signal listeners are cleaned up on normal resolution. * @returns {Promise }

(chunks, signal)

Source from the content-addressed store, hash-verified

239 * @returns {Promise<void>}
240 */
241 #createPendingWrite(chunks, signal) {
242 const { promise, resolve, reject } = PromiseWithResolvers();
243 const entry = { __proto__: null, chunks, resolve, reject };
244 this.#pendingWrites.push(entry);
245
246 if (signal) {
247 const onAbort = () => {
248 // Remove from queue so it doesn't occupy a slot
249 const idx = this.#pendingWrites.indexOf(entry);
250 if (idx !== -1) this.#pendingWrites.removeAt(idx);
251 reject(signal.reason ?? lazyDOMException('Aborted', 'AbortError'));
252 };
253
254 // Wrap resolve/reject to clean up signal listener
255 entry.resolve = function() {
256 signal.removeEventListener('abort', onAbort);
257 resolve();
258 };
259 entry.reject = function(reason) {
260 signal.removeEventListener('abort', onAbort);
261 reject(reason);
262 };
263
264 signal.addEventListener('abort', onAbort, { __proto__: null, once: true });
265 }
266
267 return promise;
268 }
269
270 /**
271 * Signal end of stream. Returns total bytes written.

Callers 1

writeAsyncMethod · 0.95

Calls 5

resolveFunction · 0.70
rejectFunction · 0.70
removeEventListenerMethod · 0.65
addEventListenerMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected