Skip to content
Permalink
Browse files

process: emit unhandled warning immediately

PR-URL: #24632
Fixes: #24209
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
  • Loading branch information...
apapirovski authored and BethGriggs committed Nov 24, 2018
1 parent 3811817 commit 5bca4c7cc0c7e712d70347fa84f8b015f0c5fadd
Showing with 22 additions and 4 deletions.
  1. +3 −4 lib/internal/process/promises.js
  2. +19 −0 test/parallel/test-promises-unhandled-rejections.js
@@ -108,7 +108,7 @@ function emitPromiseRejectionWarnings() {
}
}

let hadListeners = false;
let maybeScheduledTicks = false;
let len = pendingUnhandledRejections.length;
while (len--) {
const promise = pendingUnhandledRejections.shift();
@@ -118,10 +118,9 @@ function emitPromiseRejectionWarnings() {
const { reason, uid } = promiseInfo;
if (!process.emit('unhandledRejection', reason, promise)) {
emitWarning(uid, reason);
} else {
hadListeners = true;
}
maybeScheduledTicks = true;
}
}
return hadListeners || pendingUnhandledRejections.length !== 0;
return maybeScheduledTicks || pendingUnhandledRejections.length !== 0;
}
@@ -699,3 +699,22 @@ asyncTest('Rejected promise inside unhandledRejection allows nextTick loop' +
process.nextTick(() => promise.catch(() => done()));
});
});

asyncTest(
'Unhandled promise rejection emits a warning immediately',
function(done) {
clean();
Promise.reject(0);
const { emitWarning } = process;
process.emitWarning = common.mustCall((...args) => {
if (timer) {
clearTimeout(timer);
timer = null;
done();
}
emitWarning(...args);
}, 2);

let timer = setTimeout(common.mustNotCall(), 10000);
},
);

0 comments on commit 5bca4c7

Please sign in to comment.
You can’t perform that action at this time.