/**
 * Backpressure Controller
 *
 * Manages flow control for streams to prevent memory overflow
 * and handle slow consumers gracefully.
 */
import { EventEmitter } from 'events';
export interface BackpressureOptions {
    /** High water mark - pause producer when buffer exceeds this */
    highWaterMark?: number;
    /** Low water mark - resume producer when buffer drops below this */
    lowWaterMark?: number;
    /** Maximum time to wait for buffer drain in milliseconds */
    drainTimeout?: number;
    /** Strategy for handling overflow */
    overflowStrategy?: 'block' | 'drop' | 'error';
}
export interface BackpressureStats {
    totalChunks: number;
    droppedChunks: number;
    pauseCount: number;
    resumeCount: number;
    currentBufferSize: number;
    isPaused: boolean;
    overflowCount: number;
    avgDrainTime: number;
}
export type BackpressureState = 'flowing' | 'paused' | 'drained' | 'overflow';
export declare class BackpressureController<T = unknown> extends EventEmitter {
    private buffer;
    private state;
    private options;
    private stats;
    private drainResolvers;
    private drainTimes;
    private lastPauseTime;
    constructor(options?: BackpressureOptions);
    private createInitialStats;
    /**
     * Push a chunk into the buffer
     * Returns true if accepted, false if dropped/blocked
     */
    push(chunk: T): Promise<boolean>;
    /**
     * Pull a chunk from the buffer
     */
    pull(): T | undefined;
    /**
     * Pull all chunks from the buffer
     */
    pullAll(): T[];
    /**
     * Wait for buffer to drain below low water mark
     */
    waitForDrain(): Promise<void>;
    /**
     * Process an async iterable with backpressure control
     */
    process(source: AsyncIterable<T>): AsyncGenerator<T, void, unknown>;
    /**
     * Apply backpressure to an async generator
     */
    apply(source: AsyncIterable<T>, consumer: (chunk: T) => Promise<void>): AsyncGenerator<T, void, unknown>;
    private handleOverflow;
    private pause;
    private resume;
    private drain;
    /**
     * Get current state
     */
    getState(): BackpressureState;
    /**
     * Get current buffer size
     */
    getBufferSize(): number;
    /**
     * Check if buffer is full
     */
    isFull(): boolean;
    /**
     * Check if buffer is empty
     */
    isEmpty(): boolean;
    /**
     * Check if currently paused
     */
    isPaused(): boolean;
    /**
     * Get statistics
     */
    getStats(): BackpressureStats;
    /**
     * Get fill percentage
     */
    getFillPercentage(): number;
    /**
     * Reset controller
     */
    reset(): void;
    /**
     * Clear buffer without resetting stats
     */
    clear(): void;
    /**
     * Update options dynamically
     */
    updateOptions(options: Partial<BackpressureOptions>): void;
}
/**
 * Create a backpressure-controlled async generator
 */
export declare function withBackpressure<T>(source: AsyncIterable<T>, options?: BackpressureOptions): AsyncGenerator<T, void, unknown>;
