Ask a question about Node asynchronous callback principle.

  node.js, question

The code I am now constructing is as follows:

exports.testHandler = function(callback){
 
 console.log('testHandler start');
 var i = 0;
 function iterator(item, cb){
 Icaga;
 fs.readFile('E://file.txt','utf-8',function(err, data){
 cb(null);
 });
 bracket
 
 async.map(array, iterator, function(err, results){
 console.log('testHandler end');
 return callback(err);
 });
 bracket

This function will be called concurrently in the web project (for example, 10 http requests and this function will be triggered at the same time). Therefore, according to the single-thread asynchronous mechanism of node, this function of testHandler will be called continuously when the file IO is operated.
My question is, when fs.readFile completes the callback, how will the system record the callback and how will it handle the local variable I above? Because, if it is a traditional single-threaded program, the callback function address given by the function call is unique (an address of a code segment in memory), and local variables can be found in the corresponding stack (function Call stack). When node calls back, how does it know which function to call back and which request the local variable corresponds to?

Personally, I think there is basically no problem in the understanding of the subject.

As a function object, there is only one callback function in memory. The difference is that it generates a new execution context each time it is called. As a callback function, it takes up a separate event loop Period each time it is called.

As for where variables such as I are stored, of course they can be considered to be stored in the execution context. After the callback function is executed, if these variables are not referenced by other functions, they may be recycled.

In addition, although your http requests are concurrent, their corresponding callback functions are executed serially. This is also an important feature of JavaScript.