js如何使用promise实现多个任务队列的中断和恢复?
网友回复
<script type="text/javascript"> class PromiseQueue { constructor() { this.queue = []; this.paused = false; } addTask(task) { return new Promise((resolve, reject) => { const wrapper = () => { if (this.paused) { this.queue.push(wrapper); } else { task().then(resolve).catch(reject); } }; this.queue.push(wrapper); if (this.queue.length === 1) { wrapper(); } }); } start() { ...
点击查看剩余70%