Re:Show HN: Cancelable async primitives for JavaScript
by photonios on Tuesday August 08, 2017 @04:01PM
(#14961919)
Here's an example: in Bluebird, cancelation doesn't
propagate upstream. After registering onCancel in a
promise constructor, you have to call .cancel() on
that exact promise object. Calling .cancel() in any
child promise created with .then() or .catch() will
not abort the work, rendering the feature useless for
the most common use case!
True cancelation must propagate upstream, prevent
all pending work, and immediately free resources and memory.
From the README
Re:Show HN: Cancelable async primitives for JavaScript
by code-e on Tuesday August 08, 2017 @04:33PM
(#14962297)
But the linked bluebird docs says:
As an optimization, the cancellation signal propagates
upwards the promise chain so that an ongoing operation e.g.
network request can be aborted.
Re:Show HN: Cancelable async primitives for JavaScript
by Mitranim on Tuesday August 08, 2017 @04:49PM
(#14962524)
Interesting! This must be new. Bluebird didn't have upstream cancelation last time I checked. Now it might actually be viable. Should update the readme. Thanks!
Unfortunately it's still not viable in the browser due to its size, promises too easily get converted into non-cancelables, and worst of all, async/await forces native promises. If you want cancelable coroutines, you're forced to roll a generator-based implementation such as what Posterus provides.
Re:Show HN: Cancelable async primitives for JavaScript
by sampl on Tuesday August 08, 2017 @04:23PM
(#14962148)
D'oh, thanks
Re:Show HN: Cancelable async primitives for JavaScript
by inglor on Tuesday August 08, 2017 @06:25PM
(#14963515)
Am bluebird collaborator - confirming cancellation does everything this library does - but also componses and ref-counts to work with one-to-many flawlessly.
Re:Show HN: Cancelable async primitives for JavaScript
by Mitranim on Wednesday August 09, 2017 @08:49AM
(#14968101)
Glad it works for you!
Kind of answered in another subthread: https://news.ycombinator.com/item?id=14963524
http://bluebirdjs.com/docs/api/cancellation.html