(tasks, limit)
| 1006 | |
| 1007 | // 自定义并发控制函数 |
| 1008 | async function limitConcurrency(tasks, limit) { |
| 1009 | const results = [] |
| 1010 | const executing = [] |
| 1011 | |
| 1012 | for (const task of tasks) { |
| 1013 | const promise = task() // 执行任务 |
| 1014 | results.push(promise) |
| 1015 | |
| 1016 | if (executing.length >= limit) { |
| 1017 | await Promise.race(executing) |
| 1018 | } |
| 1019 | |
| 1020 | executing.push(promise) |
| 1021 | promise |
| 1022 | .then(() => { |
| 1023 | const index = executing.indexOf(promise) |
| 1024 | if (index !== -1) executing.splice(index, 1) |
| 1025 | }) |
| 1026 | .catch(() => { |
| 1027 | const index = executing.indexOf(promise) |
| 1028 | if (index !== -1) executing.splice(index, 1) |
| 1029 | }) |
| 1030 | } |
| 1031 | |
| 1032 | return Promise.all(results) |
| 1033 | } |
| 1034 | |
| 1035 | async function reloadAppSubCaches() { |
| 1036 | $.msg($.name, '更新订阅: 开始!') |
no outgoing calls
no test coverage detected
searching dependent graphs…