~ knotless Search/
↑↓ move↵ open⇧↵ all results

socialweb.computer/socialweb-computer-kcp

socialweb.computer: a compute market on atproto (kcp)

1 collaborator
0
0
16 lines · 287 B Raw History
export class EventBus<T> {
  #subs = new Set<(msg: T) => void>();

  subscribe(fn: (msg: T) => void): () => void {
    this.#subs.add(fn);
    return () => {
      this.#subs.delete(fn);
    };
  }

  publish(msg: T): void {
    for (const fn of this.#subs) {
      fn(msg);
    }
  }
}