最近比较忙,有时间完善思路。
关键代码
export function promiseQueue(executors: any[]) {
return new Promise((resolve, reject) => {
if (!Array.isArray(executors)) { executors = Array.from(executors); }
if (executors.length <= 0) { return resolve([]); }
const res: any[] = [];
executors = executors.map((x, i) => () => {
const p = typeof x === 'function' ? new Promise(x) : Promise.resolve(x);
p.then(response => {
res[i] = response;
if (i === executors.length - 1) {
resolve(res);
} else {
executors[i + 1]();
}
}, reject);
});
executors[0]();
});
}
本文介绍了如何在Vue中实现一个队列自动机,虽然内容暂未完全展开,但提到了关键代码作为实现的基础。

1497

被折叠的 条评论
为什么被折叠?



