Code-quality review nits: IEventBus.subscribe docstring said "debug tag" but InMemoryEventBus actually ignores the param entirely. Also add a comment to InMemoryEventBus.publish noting that under failFast only the first rejection rethrows; other failures are intentionally dropped. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
24 lines
726 B
TypeScript
24 lines
726 B
TypeScript
import type { z } from "zod";
|
|
import type { EventDescriptor } from "./event-descriptor";
|
|
|
|
export type EventHandler<T> = (event: T) => Promise<void>;
|
|
|
|
export interface IEventBus {
|
|
publish<T>(
|
|
descriptor: EventDescriptor<string, z.ZodType<T>>,
|
|
payload: T,
|
|
): Promise<void>;
|
|
|
|
/**
|
|
* Subscribe a handler. `consumerFeature` is the kebab-case name of the
|
|
* subscribing feature (e.g., "marketing-pages"). It is unused by
|
|
* InMemoryEventBus; PayloadJobsEventBus uses it to name the fan-out task
|
|
* slug deterministically (`__events.<event>.<consumerFeature>`).
|
|
*/
|
|
subscribe<T>(
|
|
descriptor: EventDescriptor<string, z.ZodType<T>>,
|
|
consumerFeature: string,
|
|
handler: EventHandler<T>,
|
|
): void;
|
|
}
|