关于javascript:reduce函数封装Promise队列

3次阅读

共计 268 个字符,预计需要花费 1 分钟才能阅读完成。

总结:其外围原理在于如果 return 回一个新的 Promise,下一个 then 解决的是这个 Promise,会期待这个 Promise 产生扭转。

    (function queue(args) {args.reduce((promise, cul) => {return promise.then((_) => {return new Promise((resolve) => {setTimeout(() => {console.log(cul);
              resolve();}, 1000);
          });
        });
      }, Promise.resolve());
    })([1, 2, 3, 4, 5, 6]);
正文完
 0