标签:dos some ons class resolve ret rom span 队列
有时候我不希望所有动作一起发生,而是按照一定顺序,逐个进行
var promise=doSomething(); promise=promise.then(doSomethingElse); promise=promise.then(doSomethingElse2); promise=promise.then(doSomethingElse2);
function queue(things){ let promise=Promise.resolve(); things.forEach(element => { promise=promise.then(()=>{ return new Promise(resolve=>{ setTimeout(() => { console.log(element) resolve(‘ok‘); }, 1000); }); }) }); } queue([‘h1‘,‘h2‘,‘h3‘]);
标签:dos some ons class resolve ret rom span 队列
原文地址:https://www.cnblogs.com/richard1015/p/9155683.html