Re: Promises (Re: New Editor's Draft of MediaStream Image Capture)

On 9/10/14 10:07 PM, cowwoc wrote:
> On 10/09/2014 7:25 PM, Silvia Pfeiffer wrote:
>> Promises is still a very new concept. I've not seen any very large 
>> application written solely with promises. In fact, Java is dropping 
>> promises and moving to callbacks. It's not proven that either is 
>> better. I'd be happy to run with both for a while. Deprecation of any 
>> old style api should go slowly over years and not suddenly. In short: 
>> I'd prefer we are stuck with callback "forever" (ie. For likely the 
>> next decade).
>
> I don't think Java's java.util.concurrent.Future was really anything 
> like Javascript Promises. I see Javascript promises used more like 
> callbacks and most Java code I've seen used Future.get() to 
> synchronize/pass data between two threads. That's quite a different 
> model than what you get under Javascript.
>
> What do you believe is different between Javascript Promises and 
> callbacks? From my point of view, Promises are just a design pattern 
> for structuring callbacks. I believe Promises are a good way of making 
> callback handling more consistent. At last check, there was some 
> inconsistency in the way we handled callbacks and decided which 
> exceptions are thrown immediately versus returned by the callbacks. 
> Promises would fix most of that.

I agree. Java is entirely different from JavaScript when it comes to 
concurrency. You can block in Java. In contrast, anything in JavaScript 
that takes any time at all you can't wait for and have to get back to 
later instead with a callback, making the sequence of things hard to 
follow, and error-handling hard to get right. Promises, in contrast, let 
you compose async callback chains in natural order.

On-top of a standard pattern, we get tools like Promise.all(a,b,c) and 
Promise.race(a,b,c)  to let multiple things advance in parallel!

Getting that right without promises is almost heartbreakingly hard, 
which ironically is what the code in the bug ekr just mentioned didn't 
(the code was attempting to do two async-things in parallel and 
erroneously overloaded one of the inputs to try to avoid the two 
callbacks racing and doing the final step twice).

.: Jan-Ivar :.

Received on Thursday, 11 September 2014 04:56:55 UTC