UNPKG

digitaltwin-core

Version:

Minimalist framework to collect and handle data in a Digital Twin project

71 lines 2.31 kB
/** * @fileoverview Event system for digital twin engine component communication * * This module provides a centralized event bus for components to communicate * asynchronously about their execution status and data processing events. */ import { EventEmitter } from 'events'; /** * Enhanced event bus for digital twin engine component communication. * * Extends Node.js EventEmitter to provide type-safe event handling * for component lifecycle events. All components can emit events * to notify other parts of the system about their execution status. * * @example * ```typescript * // Listen for collector completion events * engineEventBus.on('collector:completed', (event) => { * console.log(`Collector ${event.componentName} completed at ${event.timestamp}`); * }); * * // Emit an event from a component * engineEventBus.emit('collector:completed', { * type: 'collector:completed', * componentName: 'my-collector', * timestamp: new Date(), * data: { success: true } * }); * ``` */ export class EngineEventBus extends EventEmitter { /** * Emits a component event to all registered listeners. * * @param event - The event name/type to emit * @param data - The component event data * @returns True if the event had listeners, false otherwise */ emit(event, data) { return super.emit(event, data); } /** * Registers a listener for component events. * * @param event - The event name/type to listen for * @param listener - Function to call when the event is emitted * @returns This event bus instance for method chaining */ on(event, listener) { return super.on(event, listener); } } /** * Global event bus instance for the digital twin engine. * * This singleton provides a centralized communication channel * for all components within the digital twin system. * * @example * ```typescript * // Listen for all collector events * engineEventBus.on('collector:completed', (event) => { * console.log(`Collector completed: ${event.componentName}`); * }); * * // Components emit events through this bus * engineEventBus.emit('collector:completed', eventData); * ``` */ export const engineEventBus = new EngineEventBus(); //# sourceMappingURL=events.js.map