Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected upward cancellation propagation #1459

Closed
jsor opened this issue Sep 22, 2017 · 0 comments

Comments

@jsor
Copy link

commented Sep 22, 2017

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);
});
});

This was referenced Oct 11, 2019
This was referenced Oct 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.