export default class EventHandler<EventType>{
    public eventRegistry: ((event: EventType) => void|Promise<void>)[] = [];

    public add(callback: (event: EventType) => void|Promise<void>): void {
        this.eventRegistry.push(callback);
    }

    public remove(callback: (event: EventType) => void|Promise<void>): void {
        this.eventRegistry = this.eventRegistry.filter(c => c !== callback);
    }

    public emit(event: EventType): void {
        for (let i = 0; i < this.eventRegistry.length; i++) {
            this.eventRegistry[i](event);
        }
    }

    public clear(): void {
        this.eventRegistry = [];
    }
}