Kris Zyp wrote:
> I believe that the overwhelming need that is continually and 
> constantly expressed and felt in the JS community in terms of handling 
> asynchronous activity is fundamentally a cry for top-down controlled 
> single-frame continuations (obviously not always stated in such terms, 
> but that is the effective need/solution). In terms of an actual code 
> example, essentially what is desired is to be able to write functions 
> like:
>
> element.onclick = function(){
>     // suspend execution after doSomethingAsync() to wait for result
>     var result = <some operator> doSomethingAsync();
>     // resume and do something else
>     alert(result);
> };
>
I really like the direction that this is going, but I'm curious: Why not 
look into having full coroutines support? Coroutines support the above 
pattern well, plus they can be used to implement generators using the 
same mechanisms (although slightly differently than JS1.7/Python 
generators.) To allow code to suspend execution as you have shown above 
while avoiding reentrancy, you'll need some kind of "fork" or "spawn" 
primitive as well, and coroutines provide a nice paradigm for that.

-Eric

Kris Zyp wrote:
I believe that the overwhelming need that is continually and constantly expressed and felt in the JS community in terms of handling asynchronous activity is fundamentally a cry for top-down controlled single-frame continuations (obviously not always stated in such terms, but that is the effective need/solution). In terms of an actual code example, essentially what is desired is to be able to write functions like:

element._onclick_ = function(){
    // suspend execution after doSomethingAsync() to wait for result
    var result = <some operator> doSomethingAsync();
    // resume and do something else
    alert(result);
};

I really like the direction that this is going, but I'm curious: Why not look into having full coroutines support? Coroutines support the above pattern well, plus they can be used to implement generators using the same mechanisms (although slightly differently than JS1.7/Python generators.) To allow code to suspend execution as you have shown above while avoiding reentrancy, you'll need some kind of "fork" or "spawn" primitive as well, and coroutines provide a nice paradigm for that.

-Eric

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to