On Oct 19, 2011, at 12:55 PM, Eric Jacobs wrote:

> 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?

Asked and answered many times, e.g.

https://mail.mozilla.org/pipermail/es-discuss/2006-June/003497.html

on the implementation problems with requiring suspending across native frames.

The other objection is that (ignoring some evil native APIs such as sync XHR) 
JS has run-to-completion execution model now. You can model

  assert_invariants();
  f();
  assert_invariants_not_affected_by_f_etc();

where "etc" means functions called from f. No data races, no preemption points 
even if "voluntary" -- the immediately preempted function may have volunteered, 
but in programming in the large, the sum of its ancestors in all call graphs 
may well *not* have volunteered to lose their invariants.

This second objection is not an implementor issue, rather a 
security/integrity/pedagogy concern. It's a big one too.

/be


> 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
> 
> <..html>_______________________________________________
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to