File tree Expand file tree Collapse file tree 2 files changed +22
-4
lines changed
Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -108,7 +108,7 @@ function emitPromiseRejectionWarnings() {
108108 }
109109 }
110110
111- let hadListeners = false;
111+ let maybeScheduledTicks = false;
112112 let len = pendingUnhandledRejections.length;
113113 while (len--) {
114114 const promise = pendingUnhandledRejections.shift();
@@ -118,10 +118,9 @@ function emitPromiseRejectionWarnings() {
118118 const { reason, uid } = promiseInfo;
119119 if (!process.emit('unhandledRejection', reason, promise)) {
120120 emitWarning(uid, reason);
121- } else {
122- hadListeners = true;
123121 }
122+ maybeScheduledTicks = true;
124123 }
125124 }
126- return hadListeners || pendingUnhandledRejections.length !== 0;
125+ return maybeScheduledTicks || pendingUnhandledRejections.length !== 0;
127126}
Original file line number Diff line number Diff line change @@ -699,3 +699,22 @@ asyncTest('Rejected promise inside unhandledRejection allows nextTick loop' +
699699 process.nextTick(() => promise.catch(() => done()));
700700 });
701701});
702+
703+ asyncTest(
704+ 'Unhandled promise rejection emits a warning immediately',
705+ function(done) {
706+ clean();
707+ Promise.reject(0);
708+ const { emitWarning } = process;
709+ process.emitWarning = common.mustCall((...args) => {
710+ if (timer) {
711+ clearTimeout(timer);
712+ timer = null;
713+ done();
714+ }
715+ emitWarning(...args);
716+ }, 2);
717+
718+ let timer = setTimeout(common.mustNotCall(), 10000);
719+ },
720+ );
You can’t perform that action at this time.
0 commit comments