Last active
December 19, 2015 19:08
-
-
Save bradorego/6003652 to your computer and use it in GitHub Desktop.
trivial server.js example for vertx hanging bug
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 vertx = require('vertx'), | |
console = require('vertx/console'), | |
client = vertx.createHttpClient().host('google.com'), | |
rm = new vertx.RouteMatcher(); | |
rm.get('/', function (req) { | |
var request, | |
request2, | |
isReq2Finished = false; | |
request = client.get("/", function (resp) { | |
////do something with the response | |
console.log("resp1: " + resp.statusCode() + " - " + resp.statusMessage()); | |
req.response.statusCode(resp.statusCode()); | |
req.response.statusMessage(resp.statusMessage()); | |
resp.bodyHandler(function (body) { | |
///do something with the body | |
vertx.setPeriodic(200, function (id) { | |
if (!isReq2Finished) { | |
return; | |
} | |
vertx.cancelTimer(id); | |
console.log("body1: " + body.toString()); | |
req.response.end(body); | |
client.close(); | |
}); | |
}); | |
}); | |
request.end(); | |
////send another request to get other info needed | |
request2 = client.get("/maps", function (resp2) { | |
console.log("resp2: " + resp2.statusCode() + " - " + resp2.statusMessage()); | |
resp2.bodyHandler(function (body2) { | |
///do something with the body | |
console.log("body2: " + body2.toString()); | |
isReq2Finished = true; | |
}); | |
}); | |
request2.end(); | |
}); | |
rm.get('/another-route', function () { | |
var request; | |
request = client.get("/docs", function (resp) { | |
req.response.end("Another route!"); | |
client.close(); | |
}); | |
}); | |
vertx.createHttpServer().requestHandler(rm).requestHandler(function (req) { | |
//// trivial in this case, but still part of the app structure | |
rm.call(req); | |
}).listen(8080, function () { | |
console.log("listening on 8080"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment