All files fanout.ts

100% Statements 10/10
100% Branches 0/0
100% Functions 5/5
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17  1x 1x     3x     10x     5x 5x 9x     1x
export type FanOutUnsubscribe = () => void;
export type FanOutListener<D> = (data: D) => void;
 
export class FanOut<D> {
  public readonly listeners = new Set<FanOutListener<D>>();
 
  public emit(data: D): void {
    this.listeners.forEach((listener) => listener(data));
  }
 
  public listen(listener: FanOutListener<D>): FanOutUnsubscribe {
    const listeners = this.listeners;
    listeners.add(listener);
    return () => listeners.delete(listener);
  }
}