[英]Async/Await is awaiting another?
我有异步 function:
const getUser = async (query) => {
const user = await Users.findOne(query);
const feed = await Feeds.findOne({ user: user._id });
console.log("Do this befor await above");
return { user, feed };
};
是不是意味着JS在每条await线上都有延迟,等待promise结果和console.log("Do this befor await above");
从来没有在上面两个await
之前运行? 是否有可能最后一个等待比第一个更快返回,我得到了这个:
return {undefined, feed}
?
那么,异步调用后的代码不会阻塞吗?
getUser();
console.log("Code below is not blocking...");
假设findOne
实际上返回 promise:
是不是意味着JS在每条await线上都有延迟,等待promise结果
是的
和 console.log("在上面的等待之前执行此操作"); 从来没有在上面两个 await 之前运行?
是的
是否有可能最后一个等待比第一个更快返回,我得到了这个:
不,直到Feeds.findOne
返回的Users.findOne
解决后,才会调用 Feeds.findOne。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.