-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Closed
Description
Using [email protected]
, I've noticed that processes will not shutdown until the timeout has triggered, even if the promise is cancelled.
In this example, I would have expected the process to shutdown after roughly 1s, but the process will take about 10 seconds before shutting down, due to the setTimeout
reference called from promise.timeout
still being active.
var Promise = require('bluebird');
Promise.config({ cancellation: true });
process.on('exit', function() {
console.log(new Date(), 'Process exiting');
});
console.log(new Date(), 'Starting');
var p = new Promise(function(resolve, reject, onCancel) {
onCancel(function() {
console.log(new Date(), 'Cancelled');
});
})
.timeout(10000);
// Wait 1s, the
setTimeout(function() {
console.log(new Date(), 'Cancelling promise');
p.cancel();
}, 1000);
The output looks like this
Fri Dec 18 2015 11:22:00 GMT+0000 (GMT) 'Starting'
Fri Dec 18 2015 11:22:01 GMT+0000 (GMT) 'Cancelling promise'
Fri Dec 18 2015 11:22:01 GMT+0000 (GMT) 'Cancelled'
Fri Dec 18 2015 11:22:10 GMT+0000 (GMT) 'Process exiting'
Notice the 10 second delay on the last log line.