bacnet-device
Version:
A TypeScript library for implementing BACnet IP devices in Node.js.
66 lines • 2.31 kB
TypeScript
/**
* Event handling module for BACnet devices
*
* This module provides an asynchronous event system for BACnet components.
* The implementation is inspired by Node.js's native EventEmitter but supports
* asynchronous event handlers.
*
* @module
*/
/**
* Type mapping for event names to their argument arrays
*
* @typeParam T - An interface mapping event names to their argument arrays
* @private
*/
export type BDEventMap<T> = Record<keyof T, any[]>;
/**
* Extracts the argument types for a specific event
*
* @typeParam T - An event map interface
* @typeParam K - The event name to extract arguments for
* @private
*/
export type BDEventArgs<T, K extends keyof T> = T[K];
/**
* Type for event listeners/handlers
*
* @typeParam T - An event map interface
* @typeParam K - The event name this listener handles
* @private
*/
export type BDEventListener<T, K extends keyof T> = T[K] extends unknown[] ? (...args: T[K]) => Promise<void> : never;
/**
* Implements an event emitter, conceptually similar to Node.js' native
* EventEmitter, that supports asynchronous event handlers/listeners.
*
* This class provides a foundation for event-based communication between
* BACnet components. It allows objects to register listeners for specific events
* and trigger those events asynchronously.
*
* @typeParam T - An interface mapping event names to their argument arrays
*/
export declare class BDEvented<T extends BDEventMap<T>> {
#private;
/**
* Creates a new Evented instance with no registered listeners
*/
constructor();
/**
* Adds a new listener for the specified event.
*
* @param event - The event name to subscribe to
* @param cb - The callback function to execute when the event is triggered
* @returns The callback function for chaining
*/
subscribe<K extends keyof T>(event: K, cb: BDEventListener<T, K>): void;
/**
* Fires an event. All subscribed listeners will be called in parallel.
*
* @param event - The event name to trigger
* @param args - The arguments to pass to each listener
* @returns A promise that resolves when all listeners have completed
*/
trigger<K extends keyof T>(event: K, ...args: BDEventArgs<T, K>): Promise<void>;
}
//# sourceMappingURL=evented.d.ts.map