我具有异步功能:
PHP Warning: PHP Startup: Unable to load dynamic library 'php_pthreads.dll' (tried: C:\xampp\php\ext\php_pthreads.dll (The specified procedure could not be found.), C:\xampp\php\ext\php_php_pthreads.dll.dll (The specified module could not be found.)) in Unknown on line 0
Warning: PHP Startup: Unable to load dynamic library 'php_pthreads.dll' (tried: C:\xampp\php\ext\php_pthreads.dll (The specified procedure could not be found.), C:\xampp\php\ext\php_php_pthreads.dll.dll (The specified module could not be found.)) in Unknown on line 0
PHP 7.4.5 (cli) (built: Apr 14 2020 16:17:34) ( ZTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
这是否意味着JS在每条等待行上等待延迟,等待承诺结果,并且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 };
};
从未在以上两个console.log("Do this befor await above");
之前运行?
可能最后一次等待返回的速度比第一个更快,然后我得到了:
await
?
那么,异步调用后的代码不会阻塞吗?
return {undefined, feed}
答案 0 :(得分:1)
假设findOne
实际上返回了一个承诺:
这是否意味着JS在每个等待行上都延迟了,等待承诺结果
是
和console.log(“在此之前等待它”);从未在两个以上等待之前运行?
是
是否可以比最后一次更快返回最后一次等待,我得到了:
不。直到Feeds.findOne
返回的诺言得到解决,Users.findOne
才被调用。