UNPKG

@juspay/neurolink

Version:

Universal AI Development Platform with working MCP integration, multi-provider support, and professional CLI. Built-in tools operational, 58+ external MCP servers discoverable. Connect to filesystem, GitHub, database operations, and more. Build, test, and

87 lines (86 loc) 2.52 kB
/** * Adaptive Semaphore Utility * * Provides a sophisticated semaphore implementation with dynamic concurrency adjustment * for optimal resource utilization and performance tuning based on response times and error rates. */ export interface AdaptiveSemaphoreConfig { initialConcurrency: number; maxConcurrency: number; minConcurrency: number; } export interface AdaptiveSemaphoreMetrics { activeRequests: number; currentConcurrency: number; completedCount: number; errorCount: number; averageResponseTime: number; waitingCount: number; } /** * Adaptive semaphore that automatically adjusts concurrency based on performance metrics */ export declare class AdaptiveSemaphore { private count; private waiters; private currentConcurrency; private activeRequests; private completedCount; private errorCount; private responseTimes; private readonly maxConcurrency; private readonly minConcurrency; constructor(config: AdaptiveSemaphoreConfig); /** * Acquire a semaphore permit, waiting if necessary */ acquire(): Promise<void>; /** * Release a semaphore permit and wake up waiting requests */ release(): void; /** * Record successful completion with response time for adaptive adjustment */ recordSuccess(responseTimeMs: number): void; /** * Record error for adaptive adjustment */ recordError(responseTimeMs?: number): void; /** * Manually adjust concurrency level */ adjustConcurrency(newLimit: number): void; /** * Get current performance metrics */ getMetrics(): AdaptiveSemaphoreMetrics; /** * Reset metrics for new batch or session */ resetMetrics(): void; /** * Automatically adjust concurrency based on performance indicators */ private adjustConcurrencyBasedOnPerformance; /** * Check if semaphore is idle (no active or waiting requests) */ isIdle(): boolean; /** * Get current concurrency limit */ getCurrentConcurrency(): number; /** * Get number of active requests */ getActiveRequestCount(): number; /** * Get number of waiting requests */ getWaitingRequestCount(): number; } /** * Factory function to create an adaptive semaphore with default configuration */ export declare function createAdaptiveSemaphore(initialConcurrency: number, maxConcurrency?: number, minConcurrency?: number): AdaptiveSemaphore;