1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import { asyncPool } from "https://esm.town/v/harryhood/asyncPool";
// A generic utility function that handles concurrency and rate-limiting
export async function rateLimitedAsyncPool<T, V>(
items: T[],
poolLimit: number,
fn: (item: T) => Promise<V>,
waitTime: number,
): Promise<V[]> {
return asyncPool(items, poolLimit, async (item) => {
const result = await fn(item);
await new Promise((resolve) => setTimeout(resolve, waitTime));
return result;
});
}