Created
May 27, 2011 21:41
-
-
Save bjouhier/996245 to your computer and use it in GitHub Desktop.
Demonstrates problem when more than 4 HTTP client requests are sent in parallel
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
var streams = require("streamline/lib/streams/streams"); | |
var flows = require("streamline/lib/util/flows"); | |
var port = 3001; | |
// if you remove last element, test will pass! | |
var values = [1,2,3,4,5]; | |
function send(_, path, val){ | |
return streams.httpRequest({ | |
method: "put", | |
url: "http://localhost:" + port + path | |
}).write(_, "" + val).end().response(_).readAll(_); | |
} | |
function reply(response, statusCode, str) { | |
response.writeHead(statusCode, { | |
"content-type": "text/plain" | |
}).end(str); | |
} | |
new streams.HttpServer(function(request, response, _){ | |
var body = request.readAll(_); | |
switch (request.url) { | |
case "/foo": | |
var futures = values.map(function(i) { | |
return send(null, "/bar", i); | |
}); | |
var result = flows.collect(_, futures).join(","); | |
reply(response, 200, result); | |
break; | |
case "/bar": | |
var result = send(_, "/zoo", 2 * parseInt(body)); | |
reply(response, 200, result); | |
break; | |
case "/zoo": | |
reply(response, 200, "#" + body); | |
break; | |
default: | |
reply(response, 404, "not found: " + request.url); | |
break; | |
} | |
}).listen(_, port); | |
console.log("server ready. try http://localhost:" + port + "/foo"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment