- 简易版
class AsyncQueue {
constructor() {
this.queue = []
this.index = 0
}
add(...fn) {
this.queue.push(...fn)
}
run() {
const fn = this.queue[this.index]
fn(this.next.bind(this))
}
next() {
if (this.index >= this.queue.length - 1) return
const fn = this.queue[++this.index]
fn(this.next.bind(this))
}
}