@juspay/neurolink
Version:
Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio
75 lines (74 loc) • 2.26 kB
TypeScript
/**
* 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.
*/
import type { AdaptiveSemaphoreConfig, AdaptiveSemaphoreMetrics } from "../../types/index.js";
/**
* 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;