【发布时间】:2016-08-05 04:34:42
【问题描述】:
在Hands-on node一书中,作者给出了阻塞I\O的例子,
var post = db.query("select * from posts where id = 1");
doSomethingWithPost(post)
doSomethingElse();
作者说在第 1 行执行完 db 查询之前什么都不执行
然后,他显示非阻塞代码
callback = function(post){
doSomethingWithPost(post)
}
db.query("select * from posts where id = 1",callback);
doSomethingElse();
在查询执行之前,这不是也阻塞了吗?
所以,doSomethingElse 在查询完成之前不会被执行。
【问题讨论】:
标签: node.js