Ron Buckton (2013-05-27T19:47:46.000Z)
github at esdiscuss.org (2013-07-12T02:27:22.565Z)
Are there a fixed number of use cases for promise subclasses? I've seen discussions about two possibilities referred to on this list, specifically a lazy-promise and a cancellable promise. I wonder if these two capabilities should instead be part of the Promise/Future API and not have subclasses promises. High-order operations like Q.all/Future.every will cause the subclass to be lost to the resulting operation. I do agree with the earlier discussion that adding a cancel method to a promise can expose too much to the consumer, allowing multiple consumers of the same promise the ability to cancel the root. I have been experimenting [1] with supplying a cancellation signal from outside the promise that can be provided to the various API's (as an optional argument to the constructor and to then/done) to allow for cancellation but respect the separation of responsibilities between a promise and its creator. This makes cancellation optional, but fully baked into the API, as well as allowing the promise to fully cooperate with cancellation internally. In a similar way we could enable lazy initialization of the promise via an argument to the constructor. Are there other use cases for promise subclasses? Not subclassing promise doesn't prevent it from being a first-class object, just as how today you can't subclass Function, yet functions are first class. [1]: http://github.com/rbuckton/promisejs Note: this is roughly based off of the DOM Futures spec with some non-spec additions, and performs auto-lift and single unwrap as discussed in an earlier thread.