(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 |
| 1081 | .then(() => { |
| 1082 | const index = executing.indexOf(promise) |
| 1083 | if (index !== -1) executing.splice(index, 1) |
| 1084 | }) |
| 1085 | .catch(() => { |
| 1086 | const index = executing.indexOf(promise) |
| 1087 | if (index !== -1) executing.splice(index, 1) |
| 1088 | }) |
| 1089 | } |
| 1090 | |
| 1091 | return Promise.all(results) |
| 1092 | } |
| 1093 | |
| 1094 | async function reloadAppSubCaches() { |
| 1095 | $.msg($.name, '更新订阅: 开始!') |
no outgoing calls
no test coverage detected