Created
April 8, 2010 23:00
-
-
Save hns/360650 to your computer and use it in GitHub Desktop.
Examples for current Async JSGI implementation in RingoJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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