File tree 2 files changed +22
-4
lines changed
2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -108,7 +108,7 @@ function emitPromiseRejectionWarnings() {
108
108
}
109
109
}
110
110
111
- let hadListeners = false ;
111
+ let maybeScheduledTicks = false ;
112
112
let len = pendingUnhandledRejections . length ;
113
113
while ( len -- ) {
114
114
const promise = pendingUnhandledRejections . shift ( ) ;
@@ -118,10 +118,9 @@ function emitPromiseRejectionWarnings() {
118
118
const { reason, uid } = promiseInfo ;
119
119
if ( ! process . emit ( 'unhandledRejection' , reason , promise ) ) {
120
120
emitWarning ( uid , reason ) ;
121
- } else {
122
- hadListeners = true ;
123
121
}
122
+ maybeScheduledTicks = true ;
124
123
}
125
124
}
126
- return hadListeners || pendingUnhandledRejections . length !== 0 ;
125
+ return maybeScheduledTicks || pendingUnhandledRejections . length !== 0 ;
127
126
}
Original file line number Diff line number Diff line change @@ -699,3 +699,22 @@ asyncTest('Rejected promise inside unhandledRejection allows nextTick loop' +
699
699
process . nextTick ( ( ) => promise . catch ( ( ) => done ( ) ) ) ;
700
700
} ) ;
701
701
} ) ;
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