[英]In nodejs, will function return before all callbacks within function have executed?
function A (req,res){
db.query(sql,cb(err,results){
//do something
}
}
When I call function A
in the code shown above, will it return before the cb
has executed? 当我在上面显示的代码中调用
function A
时,它将在cb
执行之前返回吗?
Not necessarily. 不必要。 If
db.query
is actually asynchronous, then the answer is yes. 如果
db.query
实际上是异步的,那么答案是肯定的。 However, many functions with callback-style signatures are not actually asynchronous, so it is possible that cb
will run before A
returns. 但是,许多具有回调样式签名的函数实际上并不是异步的,因此
cb
可能会在A
返回之前运行。 You should not count on either order of events in general. 一般而言,您不应指望事件的任何顺序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.