/** * SupervisorTree manages a tree of child processes with restart strategies. * Supports one_for_one, one_for_all, and rest_for_one restart strategies. * @class */ export class SupervisorTree { /** * Creates a new SupervisorTree. * @constructor * @param {string} id - Unique identifier for the supervisor * @param {string} restartStrategy - The restart strategy to use: 'one_for_one', 'one_for_all', or 'rest_for_one' * @throws {Error} If restartStrategy is invalid */ constructor(id: string, restartStrategy: string); id: string; children: Map; restartStrategy: string; /** * Adds a child to the supervisor with a specified restart strategy. * @param {string} childId - Unique identifier for the child * @param {Function} child - The child function to be supervised * @param {string} childRestartStrategy - The restart strategy for this child: 'one_for_one' or 'one_for_all' * @throws {Error} If childId is already in use or childRestartStrategy is invalid */ addChild(childId: string, child: Function, childRestartStrategy: string): void; /** * Starts all children under this supervisor. * @returns {Promise} A promise that resolves when all children are started * @throws {Error} If any child fails to start */ start(): Promise; /** * Restarts a child based on the supervisor's restart strategy. * @param {string} childId - The ID of the child to restart * @throws {Error} If childId is not found */ restart(childId: string): Promise; /** * Applies the restart strategy to the supervisor. * @private * @param {string} childId - The ID of the child that failed * @throws {Error} If restart strategy is invalid */ private _applyRestartStrategy; /** * Restarts only the specified child (one_for_one). * @private * @param {string} childId - The ID of the child to restart * @throws {Error} If childId is not found */ private _restartOneForOne; /** * Restarts all children (one_for_all). * @private * @throws {Error} If any child fails to restart */ private _restartOneForAll; /** * Restarts all children except the one that failed (rest_for_one). * @private * @param {string} childId - The ID of the child that failed * @throws {Error} If childId is not found */ private _restartRestForOne; /** * Validates the restart strategy. * @private * @param {string} strategy - The restart strategy to validate * @returns {string} The validated strategy * @throws {Error} If strategy is invalid */ private _validateRestartStrategy; }