MCPcopy
hub / github.com/rowboatlabs/rowboat / InMemoryBus

Class InMemoryBus

apps/cli/src/application/lib/bus.ts:12–35  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10}
11
12export class InMemoryBus implements IBus {
13 private subscribers: Map<string, ((event: z.infer<typeof RunEvent>) => Promise<void>)[]> = new Map();
14
15 async publish(event: z.infer<typeof RunEvent>): Promise<void> {
16 const pending: Promise<void>[] = [];
17 for (const subscriber of this.subscribers.get(event.runId) || []) {
18 pending.push(subscriber(event));
19 }
20 for (const subscriber of this.subscribers.get('*') || []) {
21 pending.push(subscriber(event));
22 }
23 await Promise.all(pending);
24 }
25
26 async subscribe(runId: string, handler: (event: z.infer<typeof RunEvent>) => Promise<void>): Promise<() => void> {
27 if (!this.subscribers.has(runId)) {
28 this.subscribers.set(runId, []);
29 }
30 this.subscribers.get(runId)!.push(handler);
31 return () => {
32 this.subscribers.get(runId)!.splice(this.subscribers.get(runId)!.indexOf(handler), 1);
33 };
34 }
35}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected