下面试ts简单写的思路代码
enum Statu {
plain,
plianing,
error,
ready,
}
// 并发数
class Parallel {
num;
files = [] as any[];
PARALLEL_NUM = 0;
async filesErrorTips () {
// doto
}
async send (index: number) {
if (!this.files[index]) return;
if (this.files[index].Statu !== Statu.plianing) {
this.send(++index);
return;
}
if (this.files[index].Size > ‘500M‘) {
await this.filesErrorTips();
this.send(++index);
return;
}
const res = await this.fetchApi();
// 错误判断
this.send(++index);
}
fetchApi () {
// todo
}
init () {
for (let i; i < this.PARALLEL_NUM; i++) {
this.send(i);
}
}
}
原文地址:https://www.cnblogs.com/liangcheng11/p/9103007.html
时间: 2024-10-07 13:28:18