I've discovered the following behaviour which i'm unsure whether that is correct or a bug (tested with v3.0.0 and latest v3.5.0).
var promise1 = new Promise(function(resolve, reject, onCancel) {
onCancel(function() {
console.log("onCancel promise1");
});
});
var promise2 = new Promise(function(resolve, reject, onCancel) {
resolve(promise1);
onCancel(function() {
console.log("onCancel promise2");
});
});
var promise3 = new Promise(function(resolve, reject, onCancel) {
resolve(promise2);
onCancel(function() {
console.log("onCancel promise3");
});
});
promise3.cancel();
I've expected the output to be
onCancel promise3
onCancel promise2
onCancel promise1
but it's actually
onCancel promise3
onCancel promise1
Bluebird is invoking the cancel callback on the root promise1 only, but not on the intermediary promise2. Is this the expected behaviour?
I've seen there is a similar test case, but it's calling finally() for all promises in between.
|
specify("cancels the followee, calling all callbacks and finally handlers", function() { |
|
var called = 0; |
|
var finalled = 0; |
|
|
|
var promise = new Promise(function(_, __, onCancel) { |
|
onCancel(function() { |
|
called++; |
|
}); |
|
}).lastly(function() { |
|
finalled++; |
|
}); |
|
|
|
var promise2 = new Promise(function(resolve, reject, onCancel) { |
|
resolve(promise); |
|
onCancel(function() { |
|
called++; |
|
}); |
|
}).lastly(function() { |
|
finalled++; |
|
}); |
|
|
|
var promise3 = new Promise(function(resolve, reject, onCancel) { |
|
resolve(promise2); |
|
onCancel(function() { |
|
called++; |
|
}); |
|
}).lastly(function() { |
|
finalled++; |
|
}); |
|
|
|
promise3.cancel(); |
|
return awaitLateQueue(function() { |
|
assert.equal(3, called); |
|
assert.equal(3, finalled); |
|
}); |
|
}); |
I've discovered the following behaviour which i'm unsure whether that is correct or a bug (tested with v3.0.0 and latest v3.5.0).
I've expected the output to be
but it's actually
Bluebird is invoking the cancel callback on the root
promise1only, but not on the intermediarypromise2. Is this the expected behaviour?I've seen there is a similar test case, but it's calling
finally()for all promises in between.bluebird/test/mocha/cancel.js
Lines 247 to 282 in a61aa1c