@push.rocks/smartproxy
Version:
A powerful proxy package with unified route-based configuration for high traffic management. Features include SSL/TLS support, flexible routing patterns, WebSocket handling, advanced security options, and automatic ACME certificate management.
60 lines (59 loc) • 1.97 kB
TypeScript
/**
* Base class for components that need proper resource lifecycle management
* Provides automatic cleanup of timers and event listeners to prevent memory leaks
*/
export declare abstract class LifecycleComponent {
private timers;
private intervals;
private listeners;
private childComponents;
protected isShuttingDown: boolean;
private cleanupPromise?;
/**
* Create a managed setTimeout that will be automatically cleaned up
*/
protected setTimeout(handler: Function, timeout: number): NodeJS.Timeout;
/**
* Create a managed setInterval that will be automatically cleaned up
*/
protected setInterval(handler: Function, interval: number): NodeJS.Timeout;
/**
* Clear a managed timeout
*/
protected clearTimeout(timer: NodeJS.Timeout): void;
/**
* Clear a managed interval
*/
protected clearInterval(timer: NodeJS.Timeout): void;
/**
* Add a managed event listener that will be automatically removed on cleanup
*/
protected addEventListener(target: any, event: string, handler: Function, options?: {
once?: boolean;
}): void;
/**
* Remove a specific event listener
*/
protected removeEventListener(target: any, event: string, handler: Function): void;
/**
* Register a child component that should be cleaned up when this component is cleaned up
*/
protected registerChildComponent(component: LifecycleComponent): void;
/**
* Unregister a child component
*/
protected unregisterChildComponent(component: LifecycleComponent): void;
/**
* Override this method to implement component-specific cleanup logic
*/
protected onCleanup(): Promise<void>;
/**
* Clean up all managed resources
*/
cleanup(): Promise<void>;
private performCleanup;
/**
* Check if the component is shutting down
*/
protected isShuttingDownState(): boolean;
}