Where'd Promise#done go?

Kevin Smith zenparsing at gmail.com
Tue Jun 18 19:55:32 PDT 2013

I am of the opinion that program errors should fail loudly by default,
which the current proposal does not support.

To this end, in my own promise implementation I use a form of "fail soon",
like so:

Define a promise tree.  As a base case we have a promise created with the
Promise constructor.  Leaves are added to the tree by using the "then"
method.  The "promise forest" is the collection of all such trees for a
running program.  An "invalid promise tree" is a tree which contains a
rejected leaf node which is not also a root.  During a "callback flush",
the callback queue is repeatedly emptied until no more callbacks remain.
 At the end of the callback flush, the promise forest is checked for any
invalid promise trees.  If there exists an invalid promise tree, then an
unhandled error is thrown (which will of course propagate to

It's worked well for me so far, and has obviated the need for bolt-ons like
"done" or "console.unlog", etc.  YMMV.


{ Kevin }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130618/2bc519e8/attachment.html>

More information about the es-discuss mailing list