Cancelable promises proposal
claude.pache at gmail.com
Fri Aug 7 19:13:54 UTC 2015
> Le 6 août 2015 à 04:20, Glen Huang <curvedmark at gmail.com> a écrit :
>> promises are fundamentally about chaining data together, not about listening for events.
> IMHO, promises are more about reacting to state change and pass down that reaction. And the reaction I'm proposing to add is "no reaction will be passed down".
Note that when you attach a reaction (through the `.then()` method) to a promise that was resolved several minutes ago, the reaction will trigger: you have to somewhat stretch you mind in order to call that "reacting to state change".
As I understand, promises are ideal for requesting and transmitting data without having to care much when the data is available (be it several minutes ago or several minutes later) — which would be managing an event. On the contrary, a "state change" sounds more like an event.
The way you think of (and use) promises will influence the way you think what "cancelling a promise" and similar actions should do. If you use promises for asking for data, "cancelling" is naturally akin to "reject with an abort signal as reason".
Now concerning your original case: "let child promises show disinterest on the result of that action". The child promise that want to show disinterest should just settle itself (for example reject itself with an abort signal, but the precise outcome may depend on the reason why you want to stop listening). That will give an appropriate signal to downstream clients, and that will prevent itself from receiving messages from upstream (because a promise cannot be settled more than once). — (True, the `.then()` method doesn’t produce a promise that could be settled prematurely: you have to construct it manually. I leave that as an exercise to the reader.)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss