Skip to main content
Glama
promise-queue.ts1.07 kB
export class PromiseQueue { private queue: Array<() => void> = []; private running = 0; constructor(private maxConcurrent: number) {} enqueue<T>(fn: () => Promise<T>): Promise<T> { return new Promise<T>((resolve, reject) => { const task = async () => { try { const result = await fn(); resolve(result); } catch (error) { reject(error); } finally { this.running--; this.processNext(); } }; if (this.running < this.maxConcurrent) { this.running++; task(); } else { this.queue.push(task); } }); } private processNext(): void { if (this.queue.length > 0 && this.running < this.maxConcurrent) { const task = this.queue.shift(); if (task) { this.running++; task(); } } } }

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/superglue-ai/superglue'

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