On Mon, May 3, 2010 at 7:29 AM, Kris Zyp <
kri...@gmail.com> wrote:
> Promise/A allows promises libraries to implemented and used by
> anyone, on top of and independent of the platform, without any
> burden on the platform implementor. For example, in a sense, Node is
> perfectly compatible with Promise/A, as it does not produce any
> incompatible promises, and one should be able use any promise
> library on top of it without requiring Ryan to lift a finger.
This is true of Promises/B also, since Node doesn't provide any
promises at all. I have verified that the approach works well on
Node and Rhino, on top of your event loop work.
> There are plenty of interesting things that implementers can define
> and add like promises, like cancellation, timeouts, promise/deferred
> separation (promise creation is completely up to implementers), and
> so on, and this spec leaves the doors open for all of this, AFAICT
> (only closing the door on completely opaque promises).
And Promises/B supports all of these possible extensions but does not
close the door on "catchalls" that are necessary for promises to
either forward or reject missing methods. This could be accomplished
in various ways, not all of which are Promises/B, but all of which are
compatible with Promises/B, given that we do not define which approach
is being used.
1.) A promise, instead of being a "thenable", could be an "emittable",
an object with an "emit(eventName, ...args)" method. The "emit"
method could then forward to a "then(...args)" method for the "then"
event. With this approach, the "emit" method can intercept missing
methods. This approach has the price of making objects with "emit"
properties indistinguishable from promises, in much the same way that
Promises/A does not distinguish objects with "then" properties. This
means that a promise cannot be resolved to a value with an "emit" or
"then" property.
1.a.) A promise could be an instance of a hidden or exposed prototype,
discoverable by require("common/promise").isPromise(object), in which
case all promises would be distinguishable from all other objects.
2.) A promise could be a Proxy as proposed for ES-Harmony, in which
case it could be a "thenable", with a meta "get" method that can
intercept non-supported methods and either forward rejections or
forward to remote promises.
3.) A promise could be a Function(eventName, ...args), ergo backward
compatible with Tyler Close's promises. This approach has the price
of making functions indistinguishable from promises, thus a promise
cannot be resolved to a function value.
Note that "thenables" are not sufficient for the catchall requirement
in any shape or form. The closest compatible notion is emittables
(probably "emissibles" if a dictionary writer were present).
> Actually, I have been thinking that perhaps Promise/A could and
> maybe should be even more minimized. I was wondering if we should
> eliminate specifying what .then() returns, only specifying that it
> should call the callback or error handler. This makes it even easier
> to create promises, and would lighten the spec. I think this might
> possibly help provide convergence with Kowal's vision of promises
> always being handled indirectly through a library, (since it is
> closer to opaque, although certainly not completely opaque), and
> would encourage using libraries for promises. Of course anyone who
> wants to interact directly with the promise (through then() calls)
> would presumably use a library that does then() chaining. I know I
> would.
This would certainly encourage the use of a library for the
consumption of promises, if not the production. Seems like 6.5 on one
hand half a baker's dozen on the other, and the decision should rest
entirely on the shoulders of people who would be interested in
producing and consuming these promises directly.
Kris Kowal