(tasks, limit)
| 1065 | |
| 1066 | // 自定义并发控制函数 |
| 1067 | async function limitConcurrency(tasks, limit) { |
| 1068 | const results = []; |
| 1069 | const executing = []; |
| 1070 | |
| 1071 | for (const task of tasks) { |
| 1072 | const promise = task(); // 执行任务 |
| 1073 | results.push(promise); |
| 1074 | |
| 1075 | if (executing.length >= limit) { |
| 1076 | await Promise.race(executing); |
| 1077 | } |
| 1078 | |
| 1079 | executing.push(promise); |
| 1080 | promise.then(() => { |
| 1081 | const index = executing.indexOf(promise); |
| 1082 | if (index !== -1) executing.splice(index, 1); |
| 1083 | }).catch(() => { |
| 1084 | const index = executing.indexOf(promise); |
| 1085 | if (index !== -1) executing.splice(index, 1); |
| 1086 | }); |
| 1087 | } |
| 1088 | |
| 1089 | return Promise.all(results); |
| 1090 | } |
| 1091 | |
| 1092 | async function reloadAppSubCaches() { |
| 1093 | $.msg($.name, '更新订阅: 开始!'); |
no outgoing calls
no test coverage detected