import { Disposable } from './disposable.js';
import { MaybePromise } from './promise.js';
/**
 * Represents a typed event.
 */
export interface Event<T> {
    /**
     *
     * @param listener The listener function will be call when the event happens.
     * @param thisArgs The 'this' which will be used when calling the event listener.
     * @param disposables An array to which a {{IDisposable}} will be added.
     * @return a disposable to remove the listener again.
     */
    (listener: (e: T) => any, thisArgs?: any, disposables?: Disposable[]): Disposable;
}
export declare namespace Event {
    function getMaxListeners(event: Event<unknown>): number;
    function setMaxListeners<N extends number>(event: Event<unknown>, maxListeners: N): N;
    function addMaxListeners(event: Event<unknown>, add: number): number;
    const None: Event<any>;
    /**
     * Given an event, returns another event which only fires once.
     */
    function once<T>(event: Event<T>): Event<T>;
    function toPromise<T>(event: Event<T>): Promise<T>;
    /**
     * Given an event and a `map` function, returns another event which maps each element
     * through the mapping function.
     */
    function map<I, O>(event: Event<I>, mapFunc: (i: I) => O): Event<O>;
    /**
     * Given a collection of events, returns a single event which emits whenever any of the provided events emit.
     */
    function any<T>(...events: Array<Event<T>>): Event<T>;
    function any(...events: Array<Event<any>>): Event<void>;
}
type Callback<T> = (...args: Array<(e: T) => any>) => any;
declare class CallbackList<T> implements Iterable<Callback<T>> {
    private _callbacks;
    private _contexts;
    get length(): number;
    add(callback: (...args: any[]) => any, context?: any, bucket?: Disposable[]): void;
    remove(callback: (...args: any[]) => any, context?: any): void;
    [Symbol.iterator](): ArrayIterator<(...args: any[]) => any>;
    invoke(...args: any[]): any[];
    isEmpty(): boolean;
    dispose(): void;
}
export interface EmitterOptions {
    onFirstListenerAdd?: (emitter: Emitter<any>) => void;
    onLastListenerRemove?: (emitter: Emitter<any>) => void;
}
export declare class Emitter<T = any> {
    private _options?;
    private static LEAK_WARNING_THRESHHOLD;
    private static _noop;
    private _event;
    protected _callbacks: CallbackList<T> | undefined;
    private _disposed;
    private _leakingStacks;
    private _leakWarnCountdown;
    constructor(_options?: EmitterOptions | undefined);
    /**
     * For the public to allow to subscribe
     * to events from this Emitter
     */
    get event(): Event<T>;
    protected checkMaxListeners(maxListeners: number): (() => void) | undefined;
    protected pushLeakingStack(): () => void;
    protected popLeakingStack(stack: string): void;
    /**
     * To be kept private to fire an event to
     * subscribers
     */
    fire(event: T): any;
    /**
     * Process each listener one by one.
     * Return `false` to stop iterating over the listeners, `true` to continue.
     */
    sequence(processor: (listener: (e: T) => any) => MaybePromise<boolean>): Promise<void>;
    dispose(): void;
}
export {};
//# sourceMappingURL=event.d.ts.map