node.js - Does nodejs create background task or child process to execute callback function -
does nodejs create background task or child process execute callback functions? how nodejs execute query below?
mymodel.find({}, function (err, docs) { //do thing });
nodejs
implements non-blocking i/o
achieve these callbacks in single thread. uses event-loop.
on demand of data, nodejs registers callback , send operation event loop. , when data available, callback called.
say thread executing callback a. keep executing, , finds async task. registers new callback b async task. meanwhile waiting data of b, start executing other callback c. once c completed. check if data of b available. if so, executes b. otherwise executes other callback d... , on..
read deep understanding http://blog.mixu.net/2011/02/01/understanding-the-node-js-event-loop/
Comments
Post a Comment