在动手节点一书中,作者举了一个阻塞I\O的例子,
var post = db.query("select * from posts where id = 1");
doSomethingWithPost(post)
doSomethingElse();
Run Code Online (Sandbox Code Playgroud)
作者说在第1行完成执行db查询之前没有执行任何操作
然后,他显示了非阻塞代码
callback = function(post){
doSomethingWithPost(post)
}
db.query("select * from posts where id = 1",callback);
doSomethingElse();
Run Code Online (Sandbox Code Playgroud)
在查询执行之前,这也不会阻塞吗?
因此,在查询完成之前,不会执行doSomethingElse.
node.js ×1