promise实现异步并行和异步串行

异步并行
promise.all(pronises);确保操作能并行执行,但是缺点,只要一个失败那就完蛋;
可以改进
const arr = [name1, name2, neme3];
all.map(functin(id)
{
return new Promise(function(resolve, rejict){}).then((data)=>{array.push(data)}).catch()
}
)

Promise.all(arr).then(console.log(array));

异步串行
const arr = [funtion1, funtion2];
funtion1 = function1()
{
return new promise().then(next());
}
next = ()=>
{
arr.shift();
}

你可能感兴趣的:(js,promise,异步,并行,串行)