Skip to content

Instantly share code, notes, and snippets.

@hns
Created April 8, 2010 23:00
Show Gist options
  • Save hns/360650 to your computer and use it in GitHub Desktop.
Save hns/360650 to your computer and use it in GitHub Desktop.
Examples for current Async JSGI implementation in RingoJS
include('ringo/scheduler');
exports.app2 = function myAsyncApp(request){
// Sends a message once a second 10 times
var progress, finished;
var i = 0;
var intervalId = setInterval(function(){
i++;
progress({
status: 200,
headers:{"Content-Type": "text/plain"},
body: ["Every second another message\n"]
});
if(i == 10){
finished({})
clearInterval(intervalId);
}
}, 1000);
var promise = {
then: function(onFinish, onError, onProgress){
finished = onFinish;
progress = onProgress;
}
};
return promise;
};
exports.app = function(env) {
return {
then: function(finish, progress){
setTimeout(function() {
finish({
status: 200,
headers: {},
body: ["Delayed"]
});
}, 5000);
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment