My goal was simply to see how feasible it was to write a "autoboxing"
Promise subclass that could be used for async maps, the Service Worker
API, etc.  It turns out that the subclass is quite small and
straightforward, although Promise.all() and Promise.race() won't work
as-is on these "monadic" promises.  The grisly details are mostly at
https://github.com/domenic/promises-unwrapping/issues/95#issuecomment-35077555
(and in 
https://github.com/cscott/prfun/blob/monad-wip-1b/lib/index.js#L579-L599).

Anyway, I learned a lot, and I recommend the exercise.  It turns out
that enforcing a monadic semantics causes a lot of extra
wrapping/unwrapping throughout the implementation (for example, an
extra `.then` call per element in `Promise.all` and `Promise.race`).
(Again, see the prfun monad-wip-1b branch for details.)

I also implemented bluebird's `Promise.bind` using promise subclasses.
 I'm pretty happy with how subclasses work for the current Promise
spec. (There are some corner cases, see
https://github.com/domenic/promises-unwrapping/issues/94, but I didn't
run into them in practice.)
  --scott
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to