I'm writing some testing code in Node.js that just repeatedly POSTs HTTP requests to a web-server. In simplified form:
function doPost(opts, data) {
var post_req = http.request(opts, function(res) {
res.setEncoding('utf8')
res.on('data', function (chunk) { })
})
post_req.write(JSON.stringify(data))
post_req.end()
}
setInterval(doPost, interval, opts, msg)
I'd prefer that these requests are issued sequentially, i.e. that a subsequent POST was not sent until the first POST received a response.
My question is: due to the non-blocking architecture of the underlying libuv library used by the runtime, is it possible that this code sends one POST out over the connection to the web-server, but then is able to execute another post even if a response from the server has not yet arrived?
If I imagine this with a select() loop, I'd be free to call write() for the second POST and just get EWOULDBLOCK. Or if the network drops, will it just build up a backlog of POST request queued up to the IO thread-pool? It's unclear to me what behavior I should expect in this case. Is there something I must do to enforce completion of a POST before the next POST can start?