feat(api): allow bots to search messages within a single community (#1660)

This commit is contained in:
Hampus authored and GitHub committed 2026-08-15 23:11:45 +02:00
1 parent b5285019cd
commit 490b710c61
42 files changed
+113 -75

No files matched your search

@@ -0,0 +1,19 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
export async function mapWithConcurrency<T, TResult>(
items: ReadonlyArray<T>,
concurrency: number,
mapper: (item: T, index: number) => Promise<TResult>,
): Promise<Array<TResult>> {
const results = new Array<TResult>(items.length);
let nextIndex = 0;
async function worker(): Promise<void> {
for (;;) {
const index = nextIndex++;
if (index >= items.length) return;
results[index] = await mapper(items[index]!, index);
}
}
await Promise.all(Array.from({length: Math.min(concurrency, items.length)}, () => worker()));
return results;
}