Promises

David Bruant bruant.d at gmail.com
Tue Nov 13 02:43:53 PST 2012


Le 10/11/2012 03:14, Brendan Eich a écrit :
> David Bruant wrote:
>> Personally, to synchronize different async operations, I've never 
>> read code more elegant than what Q.all offers.
>
> What about task.js's join?
>
> https://github.com/mozilla/task.js/blob/master/examples/read.html#L41
I feel it's pretty much equivalent. Maybe slightly less verbose. I'd 
write the same code with promises as:

     Q.all(read("sleep.html"), read("read.html")).then(function(f1, f2){
         out.innerHTML += "sleep.html: " + (f1.responseText.length) + "\n";
         out.innerHTML += "read.html: " + (f2.responseText.length) + "\n";
     });

> Generators + promises = tasks ;-)
It took me several months to understand the value of tasks.js and then I 
loved the idea (though I haven't used it because of the lack of 
generators in platforms). The code you linked to leaves me somehow 
uneasy, because it looks like sync code while it's async. Promises have 
this advantage that they make clear what's sync and what's async. But 
maybe I also need to step out of my comfort zone for this case...

What's the error forwarding/handling story for tasks?

David


More information about the es-discuss mailing list