20200329
Plan
- 你不知道的 js - 中卷附录
Notes
并行异步
promise 的异步并行 -- all, race all 和 race 是 promise 的静态方法,而里面每个单独的函数必须返回 promise
new Promise(res => { setTimeout(res, 1000); }) .then(() => { return Promise.all([ new Promise(res => res(1)), new Promise(res => res(2)) ]); }) .then();asynquence 提供了 gate 方法(也可以用 all 方法,是同一个东西)
ASQ(done => {
setTimeout(done, 1000);
}).gate(
done => done(1),
done => done(2)
);
明显比 Promise.all 更简洁更方便。
除了 gate 之外,还有更多的异步 api。
- 提供了 runner 可以用来运行生成器
高级异步模式
- 可迭代序列
- 事件响应 -- promise 缺乏处理事件流的能力,asynquence 提供了响应式序列