-
Notifications
You must be signed in to change notification settings - Fork 5
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
AbortablePromise #12
Comments
Seems pretty reasonable. Any reason to use new AbortablePromise((resolve, reject, onAbort) => {
// ...
onAbort(aborter);
}); instead of new AbortablePromise((resolve, reject) => {
// ...
}, aborter); ? |
The former gives you access to the original |
That makes sense; very interesting. |
I wonder why you don't use Bluebird's builtin cancellation mechanism when you extend it's Also, your lib doesn't seem to propagate cancellations to child promises:
Here the promise won't be aborted, although it should be. I do however like the approach that the |
The only reason I use Bluebird promises at all is because they're fast on node.js. But when I ship code to the browser, I always use the es6-promise polyfill by swapping out
Only |
However, even if you're chaining two
Yeah, that's the reason why we want to spec a common cancellation behaviour and API here :-) |
Other guarantees I could make with some small tweaks:
|
I would love to have this feature! I also use |
@domenic What would it take to make a formal proposal here? |
A formal spec write-up that is implemented in at least one or two of the major promise libraries. |
I'm currently using an
AbortablePromise
class that I wrote for mach with good results. The API is very simple (adds only one argument to your resolver), transparently supports propagation, and doesn't make any assumptions about whether the promise is fulfilled or rejected when you abort. Also, only one new property/method is exposed on promise objects,promise.abort
.Here's an example of what it looks like to use it:
The implementation currently makes following guarantees:
promise.abort()
a no-oppromise.then
promise.abort()
propagates to children (i.e. ifresolve
d with an abortable child promise,promise.abort()
will abort the child)It's fairly easy to layer this on top of existing promise implementations since the
Promise
constructor doesn't require any extra arguments, only the resolver.The text was updated successfully, but these errors were encountered: