1
0
mirror of https://github.com/ruanyf/es6tutorial.git synced 2025-05-24 18:32:22 +00:00

Update async.md

This commit is contained in:
hanty 2018-07-11 14:46:51 +08:00 committed by GitHub
parent a46664f54a
commit 94024df0f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -722,9 +722,10 @@ async function f() {
注意,异步遍历器的`next`方法是可以连续调用的,不必等到上一步产生的 Promise 对象`resolve`以后再调用。这种情况下,`next`方法会累积起来,自动按照每一步的顺序运行下去。下面是一个例子,把所有的`next`方法放在`Promise.all`方法里面。
```javascript
const asyncGenObj = createAsyncIterable(['a', 'b']);
const asyncIterable = createAsyncIterable(['a', 'b']);
const asyncIterator = asyncIterable[Symbol.asyncIterator]();
const [{value: v1}, {value: v2}] = await Promise.all([
asyncGenObj.next(), asyncGenObj.next()
asyncIterator.next(), asyncIterator.next()
]);
console.log(v1, v2); // a b