Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

518 B
Raw Blame
import type { Unsubscribe } from './lifecycle';

export class Emitter<T> {
  private readonly subscribers = new Set<(value: T) => void>();

  get size(): number {
    return this.subscribers.size;
  }

  subscribe(cb: (value: T) => void): Unsubscribe {
    this.subscribers.add(cb);
    return () => {
      this.subscribers.delete(cb);
    };
  }

  emit(value: T): void {
    for (const subscriber of [...this.subscribers]) {
      subscriber(value);
    }
  }

  clear(): void {
    this.subscribers.clear();
  }
}