const emittedOnce = new WeakMap();
/**
 * Emit an event exactly once per (handler, event type) pair for the
 * lifetime of the process. Safe to call on every request — subsequent
 * calls for the same handler+type are silently dropped.
 *
 * Test isolation is free: each test's fresh vi.fn() is a new function
 * reference the WeakMap has never seen.
 */
export function emitOnce(onEvent, event) {
    if (!emittedOnce.has(onEvent)) {
        emittedOnce.set(onEvent, new Set());
    }
    const fired = emittedOnce.get(onEvent);
    if (!fired.has(event.type)) {
        fired.add(event.type);
        onEvent(event);
    }
}
