BYVoid / continuation

JavaScript asynchronous Continuation-Passing Style transformation (deprecated).
Other
388 stars 42 forks source link

challenging issue #1

Closed curimit closed 12 years ago

curimit commented 12 years ago

// use continuation to create a function which can synced waiting for 1 second var stop = function() { setTimeout(continuation(), 1000); }; console.log("start"); stop(); console.log("end");

// Readme: // Due to this, I suggest to consider implement coroutine for javascript. // we can implement "continuation" by using yield initiatively and resume by callback function.

BYVoid commented 12 years ago

You should write like this:

var stop = function(ret) {
  setTimeout(continuation(), 1000);
  ret();
};
console.log("start");
stop(continuation());
console.log("end");

Because stop function is asynchronous, you should explicitly invoke call back function to pass control flow.