UNPKG

smart-saga-pattern

Version:

A library implementing the Saga pattern for microservice architecture

38 lines (37 loc) 1.12 kB
import { SagaEvent } from '../types'; /** * Type for event handler functions */ export type EventHandler = (event: SagaEvent) => Promise<void>; /** * Interface for subscribing to events in a Saga */ export interface EventSubscriber { /** * Subscribes to events on a topic * @param topic Topic to subscribe to * @param handler Handler function for events */ subscribe(topic: string, handler: EventHandler): Promise<void>; /** * Unsubscribes from events on a topic * @param topic Topic to unsubscribe from */ unsubscribe(topic: string): Promise<void>; } /** * Base implementation of EventSubscriber */ export declare abstract class BaseEventSubscriber implements EventSubscriber { /** * Subscribes to events on a topic * @param topic Topic to subscribe to * @param handler Handler function for events */ abstract subscribe(topic: string, handler: EventHandler): Promise<void>; /** * Unsubscribes from events on a topic * @param topic Topic to unsubscribe from */ abstract unsubscribe(topic: string): Promise<void>; }