@zowe/imperative
Version:
framework for building configurable CLIs
86 lines • 4.16 kB
TypeScript
import { Logger } from "../../logger/src/Logger";
import { EventCallback } from "./EventConstants";
import { Event } from "./Event";
import { IEventDisposable } from "./doc";
import { IProcessorTypes } from "./doc/IEventInstanceTypes";
/**
* ## Overview
* Each EventProcessor manages its own subscriptions, handling the addition, emission, and removal of events.
* It uses a map where event names are keys, and values are Event objects that hold detailed event information and subscriptions.
*
* An `EventProcessor` handles three main functionalities:
* - **Subscribing to Events**:
* Registration of a callback function that will be executed when that event occurs.
* - **Emitting Events**:
* Notifying other applications or parts of the same application about certain actions or changes.
* - **Managing Event Subscriptions**:
* Mapping subscribed events and their corresponding callbacks, ensuring that events are properly handled and dispatched.
*
* ### Understanding Event Types
* - **Predefined Zowe Events**:
* Zowe provides a set of predefined shared and user events that can be watched.
* - **Custom Events**:
* Applications can define their own shared and user events, allowing for custom event-driven behavior.
*
* @export
* @class EventProcessor
*/
export declare class EventProcessor {
subscribedEvents: Map<string, Event>;
eventTimes: Map<string, string>;
processorType: IProcessorTypes;
appName: string;
logger: Logger;
/**
* Constructor initializes a new instance of EventProcessor.
*
* @param {string} appName - The application's name.
* @param {IProcessorTypes} type - The type of processor (Emitter, Watcher, or Both).
* @param {Logger} [logger] - Optional logger for recording events and errors.
* @throws {ImperativeError} If the application name is not recognized.
*/
constructor(appName: string, type: IProcessorTypes, logger?: Logger);
private _subscribe;
/**
* Subscription to an event that will notify all subscribed users.
*
* @param {string} eventName - The name of the event to subscribe to.
* @param {EventCallback[] | EventCallback} callbacks - Callback functions to handle the event.
* @returns {IEventDisposable} - Object allowing management/cleanup of the subscription.
* @throws {ImperativeError} If the processor does not have the correct permissions to perform this action.
*/
subscribeShared(eventName: string, callbacks: EventCallback[] | EventCallback): IEventDisposable;
/**
* Subscription to an event that will notify a single user.
*
* @param {string} eventName - The name of the event to subscribe to.
* @param {EventCallback[] | EventCallback} callbacks - Callback functions to handle the event.
* @returns {IEventDisposable} - Object allowing management/cleanup of the subscription.
* @throws {ImperativeError} If the processor does not have the correct permissions to perform this action.
*/
subscribeUser(eventName: string, callbacks: EventCallback[] | EventCallback): IEventDisposable;
/**
* Private method to emit the event
* @private
* @param eventName Event to be emitted
* @throws {ImperativeError} - If the event cannot be emitted.
*/
private emit;
/**
* Emits an event by updating its timestamp and writing event data.
*
* @param {string} eventName - The name of the event to emit.
* @throws {ImperativeError} If the processor does not have the correct permissions to perform this action.
* @throws {ImperativeError} - If the event cannot be emitted.
*/
emitEvent(eventName: string): void;
/**
* Unsubscribes from an event, closing file watchers and cleaning up resources.
*
* @param {string} eventName - The name of the event to unsubscribe from.
* @throws {ImperativeError} If the processor does not have the correct permissions to perform this action.
* @throws {ImperativeError} - If unsubscribing fails.
*/
unsubscribe(eventName: string): void;
}
//# sourceMappingURL=EventProcessor.d.ts.map