Skip to content

Instantly share code, notes, and snippets.

@dantman
Created September 4, 2009 21:07
Show Gist options
  • Save dantman/181131 to your computer and use it in GitHub Desktop.
Save dantman/181131 to your computer and use it in GitHub Desktop.
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