1
0
mirror of https://github.com/ruanyf/es6tutorial.git synced 2025-05-25 11:12:21 +00:00
es6tutorial/docs/async.md
2015-06-04 14:17:18 +08:00

20 lines
426 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 异步操作
## co函数库
如果并发执行异步操作可以将异步操作都放入一个数组跟在yield语句后面。
```javascript
co(function* () {
var values = [n1, n2, n3];
yield values.map(somethingAsync);
});
function* somethingAsync(x) {
// do something async
return y
}
```
上面的代码允许并发三个somethingAsync异步操作等到它们全部完成才会进行下一步。