async function runPromiseByQueue(myPromises) {
return await myPromises.reduce((previousPromise, nextPromise) => {
return previousPromise.then(id => {
console.log(id);
return nextPromise;
});
});
}
var createPromise = (time, id) => {
return new Promise(res => {
setTimeout(() => {
res(id);
}, time);
});
}
var result = runPromiseByQueue([
createPromise(3000, 1),
createPromise(2000, 2),
createPromise(1000, 3)
]);
result.then(id => {
console.log(id);
});
reduce实现串行promise
最新推荐文章于 2023-02-06 15:50:49 发布