No. There is no way to cancel such a chain.
There are ways to simulate cancelable futures, though:
var someBool;
cancelIfSomeBoolIsSet(fun(x)) {
return (x) {
if (someBool) return new Completer().future;
return fun(x);
};
}
expensiveA().then(cancelIfSomeBoolIsSet(expensiveB))
.then(cancelIfSomeBoolIsSet(expensiveC))
.then(doSomethingWithCValue);
Once someBool
is set, the future-chain is effectively canceled, because the completer's future is never completed.
Note: cancelIfSomeBoolIsSet
takes a one-arg function in my example (contrary to the 0-arg function in the initial post). It would be trivial to adapt the code.