mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-27 02:38:10 -07:00
global: private xpub support part 1
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* @template Item, Result
|
||||
* @param {readonly Item[]} items
|
||||
* @param {number} limit
|
||||
* @param {(item: Item) => Promise<Result>} fn
|
||||
* @returns {Promise<Result[]>}
|
||||
*/
|
||||
export async function mapConcurrent(items, limit, fn) {
|
||||
const results = /** @type {Result[]} */ ([]);
|
||||
let next = 0;
|
||||
const workerCount = Math.min(limit, items.length);
|
||||
const workers = Array.from({ length: workerCount }, async () => {
|
||||
while (next < items.length) {
|
||||
const index = next;
|
||||
|
||||
next += 1;
|
||||
results[index] = await fn(items[index]);
|
||||
}
|
||||
});
|
||||
|
||||
await Promise.all(workers);
|
||||
|
||||
return results;
|
||||
}
|
||||
Reference in New Issue
Block a user