Created
December 8, 2009 18:10
-
-
Save hns/251860 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
exports.app = function myAsyncApp(request){ | |
return function(responder) { | |
responder.init(200, {}); | |
var i = 0; | |
var intervalId = setInterval(function(){ | |
responder.write("Every second another message"); | |
if(i++ == 10){ | |
responder.close(); | |
clearInterval(intervalId); | |
} | |
}, 1000); | |
}; | |
} | |
This file contains hidden or 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
exports.middleware = function(app) { | |
return function(request) { | |
var response = app(request); | |
if (typeof response === "function") { | |
return function(responder) { | |
// create a proxy for the responder | |
var proxy = createResponderProxy(responder); | |
// ... and overwrite whatever method you want | |
proxy.[init|write|close] = ...; | |
response(proxy); | |
}; | |
} else { | |
// sync | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment