-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Canceling a reduction #166
Comments
The promise returned by Promise.reduce cannot be chained with the promises you return from the callback, so if you want to be able to cancel it, you can't use .reduce. This should work however: // do a progress function based on which file we're processing
var pfuncDataLoad = function(p, msg) {
progress((currentLoadIndex + p*0.5) / maxLoadIndex, msg);
};
var pfuncDecompress = function(p, msg) {
progress((currentLoadIndex + 0.5 + p*0.5) / maxLoadIndex, msg);
};
var soFar = [];
var cur = Promise.resolve().cancellable();
files.forEach(function(fname) {
cur = cur.then(function() {
return fDataLoader(fname, pfuncDataLoad).then(function(data){
return loadData(data, pfuncDecompress);
})
.then(function(r) {
var ret = {
header: r[0],
batcher: r[1]
};
// TODO: This needs to be fixed for mutliple URLs
//
ret.header.name = fname.name || name;
currentLoadIndex ++;
sofar.push(ret);
})
});
});
var loaderPromise = cur.then( ... )... rest of the code |
Thanks for your response and help. I tried your solution every which way, the weird thing is that it works sometimes while other times it doesn't. The Promise.cancel is invoked but it doesn't go anywhere. I mean I don't see it being caught or raising an error anywhere. Could be something funky I am doing. I am also uncertain on how to help you reproduce this issue. |
So I took a closer look at the cancellation logic. When we do
At each level, to branch up to the parent, the code does this:
https://github.com/petkaantonov/bluebird/blob/master/js/browser/bluebird.js#L309 I feel that the top node (lets say Still investigating, just wanted to update you. I am not entirely sure what's going on, I have very little knowledge of the whole thing. Seems to me like the the |
You are right, can you check if b3a5a0d works for you as well? |
Err I mean d818ff3 |
Yes, seems to be working great! Thanks! |
It is now included in the version 1.2 release |
What would be the general strategy for canceling a
Promise.reduce
call? The promise itself cancels but the the current promise being waited upon for fulfillment is not notified of this cancellation.E.g. how can I cancel this reduction?:
https://github.com/verma/plasio/blob/master/js/ui.js#L614
The
fDataLoader
andloadData
methods are cancelable promises.The text was updated successfully, but these errors were encountered: