Initial commit

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
dinlo
2026-05-31 18:44:04 +08:00
commit 436a9631fc
8616 changed files with 1389957 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
function asyncPool(poolLimit, iterable, iteratorFn) {
let i = 0;
const ret = [];
const executing = new Set();
const enqueue = function() {
if (i === iterable.length) {
return Promise.resolve();
}
const item = iterable[i++];
const p = Promise.resolve().then(() => iteratorFn(item, iterable));
ret.push(p);
executing.add(p);
const clean = () => executing.delete(p);
p.then(clean).catch(clean);
let r = Promise.resolve();
if (executing.size >= poolLimit) {
r = Promise.race(executing);
}
return r.then(() => enqueue());
};
return enqueue().then(() => Promise.all(ret));
}
module.exports = asyncPool;