export type EventHandler = (event: Record<string, unknown>) => void;

export class EventBus {
	private subscribers = new Set<EventHandler>();

	subscribe(handler: EventHandler): () => void {
		this.subscribers.add(handler);
		return () => {
			this.subscribers.delete(handler);
		};
	}

	publish(event: Record<string, unknown>): void {
		for (const handler of this.subscribers) {
			handler(event);
		}
	}
}
