I want understand, how asynchronous functions work in nodejs internally. Suppose, I want read any file from filesystem:
fs = require('fs')
fs.readFile('/etc/hosts', 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
console.log(data);
});
What is going on, when I call fs.readFile(...)? Or, in another words, how v8 interpreter interacts with operating system (filesystem), when I call fs.readFile(...)? How v8 knows, that file reading is done, and callback must be called?