Created
September 4, 2009 21:07
-
-
Save dantman/181131 to your computer and use it in GitHub Desktop.
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
function app(env) { | |
var ostream = new MemoryStream(); | |
var times = 5; | |
setTimeout(function t() { | |
times--; | |
ostream.write((new Date).toString()) | |
ostream.write("\n"); | |
if ( times <= 0 ) | |
ostream.close(); | |
else | |
setTimeout(t, 1000); | |
}, 1000); | |
return { status: 200, headers: { 'Content-Type': 'text/plain' }, body: ostream }; | |
} | |
// or, using a output stream set on env | |
function app(env) { | |
var ostream = env["jsgi.output"]; | |
var times = 5; | |
setTimeout(function t() { | |
times--; | |
ostream.write((new Date).toString()) | |
ostream.write("\n"); | |
if ( times <= 0 ) | |
ostream.close(); | |
else | |
setTimeout(t, 1000); | |
}, 1000); | |
return { status: 200, headers: { 'Content-Type': 'text/plain' } }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment