Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Demonstrates problem when more than 4 HTTP client requests are sent in parallel
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
You can’t perform that action at this time.