You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.
async 函数中的并行执行
在
async
函数中,仅当存在await
关键词的地方表示需要等待计算结果。那么存在互不依赖的操作时,不要错失并行执行的机会。Notice: 以下示例代码中的
wait()
方法表示异步操作。因为在async
函数中的同步操作与有没有await
不对整个async
函数内部执行顺序造成影响。因为函数体中的同步操作将按照常规单线程event loop
执行,await
后如果是非Promise
对象,那么await
将 直接 返回一个包含该同步操作的Promise
对象。以上代码中,
op0
和op1
的运行关系是同步执行,即只有等到op0
执行完成后才会执行op1
。以上代码
op0
和op1
将并行执行。同时还存在以下一种并行执行的写法:
Reference
Async function(Google Developers)
ECMAScript 6 入门
The text was updated successfully, but these errors were encountered: