Closed curimit closed 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.
// 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.