MCPcopy Index your code
hub / github.com/chavyleung/scripts / limitConcurrency

Function limitConcurrency

chavy.box.js:1008–1033  ·  view source on GitHub ↗
(tasks, limit)

Source from the content-addressed store, hash-verified

1006
1007// 自定义并发控制函数
1008async 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
1035async function reloadAppSubCaches() {
1036 $.msg($.name, '更新订阅: 开始!')

Callers 1

reloadAppSubCachesFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…