0

If I execute a number of asynchronous http requests in a for loop, is the order that those sockets are added to the event loop deterministic/guaranteed to be in the order that the loop executed?

function makeRequest(n) {
  http.get("http://www.google.com/index.html?=" + n, function(res) {
    console.log("Got response: " + res.statusCode);
  }).on('error', function(e) {
    console.log("Got error: " + e.message);
  });
}

for (var i=0; i<10; i++) {
  makeRequest(i);
}

I was talking with a coworker and we were trying to figure out if this could be true. Because node event loop, libuv, and socket/OS programming is new to me, it was all speculation.

There's not really a practical programming application to this just trying to develop and understanding.

Thank you

dm03514
  • 54,664
  • 18
  • 108
  • 145

1 Answers1

1

I don't think that's guaranteed especially with keep alive and socket reuse.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445