Skip to main content
Glama
promiseUtils.ts1.14 kB
/** * Promise utility functions for bulk operations */ /** * Runs promises in parallel with concurrency limit */ export async function parallelLimit<T, R>( items: T[], limit: number, fn: (item: T) => Promise<R> ): Promise<R[]> { const results: R[] = new Array(items.length); const executing: Promise<void>[] = []; const enqueue = (index: number): Promise<void> => fn(items[index]).then((result) => { results[index] = result; }); for (let i = 0; i < items.length; i++) { const p = enqueue(i).then(() => { const idx = executing.indexOf(p as unknown as Promise<void>); if (idx >= 0) executing.splice(idx, 1); }); executing.push(p); if (executing.length >= limit) { await Promise.race(executing); } } await Promise.all(executing); return results; } /** * Runs promises with error isolation */ export async function settleAll<T>( promises: Promise<T>[] ): Promise< Array< { status: 'fulfilled'; value: T } | { status: 'rejected'; reason: unknown } > > { return Promise.allSettled(promises); } // Note: retry() removed as unused to reduce code surface

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/bgauryy/local-explorer-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server