Skip to content

Instantly share code, notes, and snippets.

@tlrobinson
Created February 3, 2010 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tlrobinson/293483 to your computer and use it in GitHub Desktop.
Save tlrobinson/293483 to your computer and use it in GitHub Desktop.
// EXAMPLE 1
// PSGI equivalent
var app = function(env) {
return function(respond) {
// do some event stuff
setTimeout(function() {
respond({ status : code, headers : headers, body : body });
}, 1000);
}
}
// AJSGI
var app = function(env) {
return { then : function(respond) {
// do some event stuff
setTimeout(function() {
respond({ status : code, headers : headers, body : body });
}, 1000);
}};
}
// EXAMPLE 2
// PSGI equivalent
var app = function(env) {
return function(respond) {
var w = respond({ status : code, headers : headers });
// do more event stuff
setTimeout(function() { w.write(body); }, 1000);
setTimeout(function() { w.close(); }, 2000);
}
}
// AJSGI
var app = function(env) {
return { then : function(respond) {
// do some event stuff
respond({ status : code, headers : headers, body : { forEach : function(write) {
return { then : function(close) {
setTimeout(function() { write(body); }, 1000);
setTimeout(function() { close(); }, 2000);
}};
}});
}};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment