16

The oldest issue on https://github.com/promises-aplus/cancellation-spec is (at the time of writing) 9 months old. I really can’t found a reliable source of information about cancellation features on ‘standard’ promises.

By now looks like the feature is implemented in bluebird, but as a library developer I don’t want to clutter my package with a full promise implementation.

What I’d like to do is simply pass a promise-like and support the cancellation-spec.

Where could I find this information?

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
Pier Paolo Ramon
  • 2,780
  • 23
  • 26

1 Answers1

19

Cancellable promises are not going to be in ES6, as ES6 promises are very minimal.

Work on cancellation in the Promises/A+ space has stalled, as we wait for library evolution to prove one approach clearly superior. The latest thinking is at this issue, which is what most libraries looking to implement cancellation seem to follow (more or less). The key points are:

  • Cancellation as a special case of rejections
  • Reactions to cancellation propagate upward in the chain, as well as the rejection itself propagating downward.

It's not clear what you mean by "simply pass a promise-like and support the cancellation-spec." Are you trying to produce thenables, under the assumption that consumers of your library will cast it, but somehow inherit some cancellation behavior afterward? That'd be a bit tricky, especially since cancellation generally depends on a specified Cancellation constructor used for rejecting the promise. If the cancellation ecosystem was more developed, the way to do this would likely be more straightforward.

As for the future, well, it's in flux! One route forward would be for someone to champion an evolution of that cancellation proposal in Promises/A+ space, getting implementer buy-in from major libraries like Q, RSVP, when, and Bluebird. Then a lot of the smaller libraries would likely buy in, and you'd have something you could probably depend on. If it proves that popular, it'd probably be considered for ECMAScript promises as well!

But that depends on a lot of people doing a lot of work, so we'll see if it happens :). It was kind of a miracle for it to happen with the base Promises/A+ spec, but who knows... it could happen again!

Domenic
  • 110,262
  • 41
  • 219
  • 271
  • 1
    Domenic, your work on the promises specification is terrific, thank you for the clarification. And yes I meant exactly that, being able to produce `cancellable` `thenable` would be awesome. How could someone be more involved in making this real? There are a lot of rough edges, like cancellation of `Promise.all` results and similar aggregates, for example. – Pier Paolo Ramon Feb 14 '14 at 15:12
  • 1
    @PierPaoloRamon You can count on Bluebird to continue supporting `Cancellable` for the foreseeable future but at this point it is 'opt in' and not 'opt out'. That is, you have to call a method on the promise in order to make it cancellable. So since as an API it has no performance 'cost' for the library at worst it will be a plugin eventually - so you can keep using it. That said I probably would not write front facing (library) code that counts on users being aware/familiar with this behavior as it is not implemented in most other libraries at this point, nor in native JS. – Benjamin Gruenbaum Feb 14 '14 at 18:37
  • 1
    I'm not sure if this is about the same thing, perhaps it's just related, but [the TC39 cancelable promises proposal](https://www.reddit.com/r/programming/comments/5j6j65/google_kills_proposed_javascript/) has been withdrawn. – user247702 Dec 20 '16 at 12:56
  • 1
    @Stijn this is the same issue. It **is** withdrawn **but** there has been very recent (last hours) movement on the topic. – Pier Paolo Ramon Dec 20 '16 at 16:53
  • @PierPaoloRamon I've only just noticed that the answerer and proposal champion are one and the same person, whoops :) – user247702 Dec 20 '16 at 17:14