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

Function processPromiseRejections

lib/internal/process/promises.js:369–416  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

367// a warning to be emitted which requires the microtask and next tick
368// queues to be drained again.
369function processPromiseRejections() {
370 let maybeScheduledTicksOrMicrotasks = !asyncHandledRejections.isEmpty();
371
372 while (!asyncHandledRejections.isEmpty()) {
373 const { promise, warning } = asyncHandledRejections.shift();
374 if (!process.emit('rejectionHandled', promise)) {
375 process.emitWarning(warning);
376 }
377 }
378
379 let needPop = true;
380 let promiseAsyncId;
381
382 const pending = pendingUnhandledRejections;
383 pendingUnhandledRejections = new SafeMap();
384
385 for (const { 0: promise, 1: promiseInfo } of pending.entries()) {
386 maybeUnhandledPromises.set(promise, promiseInfo);
387
388 promiseInfo.warned = true;
389
390 // We need to check if async_hooks are enabled
391 // don't use enabledHooksExist as a Promise could
392 // come from a vm.* context and not have an async id
393 promiseAsyncId = promise[kAsyncIdSymbol];
394 if (promiseAsyncId !== undefined) {
395 pushAsyncContext(
396 promiseAsyncId,
397 promise[kTriggerAsyncIdSymbol],
398 promise,
399 );
400 }
401
402 const { contextFrame } = promiseInfo;
403 const priorContextFrame = AsyncContextFrame.exchange(contextFrame);
404 try {
405 needPop = unhandledRejectionsMode(promise, promiseInfo, promiseAsyncId);
406 } finally {
407 AsyncContextFrame.set(priorContextFrame);
408 needPop &&
409 promiseAsyncId !== undefined &&
410 popAsyncContext(promiseAsyncId);
411 }
412 maybeScheduledTicksOrMicrotasks = true;
413 }
414 return maybeScheduledTicksOrMicrotasks ||
415 pendingUnhandledRejections.size !== 0;
416}
417
418function listenForRejections() {
419 setPromiseRejectCallback(promiseRejectHandler);

Callers 1

Calls 8

pushAsyncContextFunction · 0.85
popAsyncContextFunction · 0.85
isEmptyMethod · 0.45
shiftMethod · 0.45
emitMethod · 0.45
entriesMethod · 0.45
setMethod · 0.45
exchangeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…