/** * 连接池和资源管理 * 管理 HTTP 连接、WebSocket 连接等资源 */ import { EventEmitter } from 'node:events'; export interface PoolConfig { /** 最大连接数 */ maxConnections?: number; /** 最小连接数 */ minConnections?: number; /** 连接超时时间(毫秒) */ timeout?: number; /** 空闲连接超时时间(毫秒) */ idleTimeout?: number; /** 连接创建函数 */ create: () => Promise; /** 连接销毁函数 */ destroy: (connection: unknown) => Promise; /** 连接验证函数 */ validate?: (connection: unknown) => boolean | Promise; } /** * 连接池类 */ export declare class ConnectionPool extends EventEmitter { private pool; private waiting; private config; private cleanupInterval?; constructor(config: PoolConfig); /** * 获取连接 */ acquire(): Promise; /** * 释放连接 */ release(connection: unknown): Promise; /** * 销毁连接 */ destroy(connection: unknown): Promise; /** * 启动清理任务 */ private startCleanup; /** * 清理空闲连接 */ private cleanup; /** * 获取池状态 */ getStatus(): { total: number; inUse: number; idle: number; waiting: number; }; /** * 清空连接池 */ clear(): Promise; /** * 关闭连接池 */ close(): Promise; }