Status: New
Owner: ----

New issue 1055 by [email protected]: Add continuations (call/cc)
http://code.google.com/p/v8/issues/detail?id=1055

Continuations are a perfect match with JavaScript and event driven programming model. They could bring JS development to the whole new level.
How about async(!) alert(fetch('http://example.com/data.txt'));?

Continuations can be added with no new syntax thus without impact to standards conformance, please see Rhino as reference:
http://wiki.apache.org/cocoon/RhinoWithContinuations

Example of usage (tested on Rhino):

// global scope continuation terminates execution
var yield = new Continuation();
function fetch(url) {
  var xhr = new XMLHttpRequest();
  var c = new Continuation(); // refers to the caller
  xhr.onreadystatechange = function() {
    if (xhr.readyState==4) {
      if (xhr.status==200) {
        c(xhr.responseText);  // set return value upon continuation
      } else {
        c(null);
      }
    }
  }
  xhr.open("GET", url, true);
  xhr.send(null);
  yield(); // terminate execution
}

Even though it may take time to get browsers support it can already be greatly beneficial in other environments.

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to