I'll try to rephrase your question, because there is a lot confusion in "Async function call" and "Async IO" terminology.
Let's write it that way: Given code below, and without looking at "foo" source code, can we run some test to say if output is going to be "Line 1\nLine2" or "Line 2\nLine1"?
var t1 = asyncTestCapture();
foo(function() {
console.log("Line 1");
});
console.log("Line 2");
var out12vsOut21 = asyncTestVerify(t1);
Answer number 1: don't try to rely on this order with exception for a well known standard function with callback parameters (Array's forEach, map, etc, String replacer, JSON reviver)
Answer number 2: (note that I tested the code very briefly and it's node.js specific, but I believe it can answer "out12vsOut21" question. Also note that I'm using undocumented node functions)
function asyncTestCapture() {
return {
activeHandles: process._getActiveHandles(),
activeRequests: process._getActiveRequests()
};
}
function asyncTestVerify(handles1) {
var handles2 = asyncTestCapture();
return handles2.activeHandles === handles1.activeHandles && handles2.activeRequests === handles1.activeRequests
}
I'll repeat again: if you need the code above there is something wrong in your design. You don't need to know "out12vsOut21" order, build your code the way it does not depend on "async or not foo is"