state-switch
Version:
State Switch is a Change Monitor/Guarder for Async Actions.
60 lines • 1.96 kB
TypeScript
/**
*
* StateSwitch for easy managing the states with async programming
*
* Class StateSwitch
* Licenst: Apache-2.0
* https://github.com/huan/state-switch
*
* Helper Class for Manage State Change
*/
import type { Loggable } from 'brolog';
import type { StateSwitchInterface, StateSwitchOptions } from './interfaces.js';
import { StateSwitchEventEmitter, Pending, StateType } from './events.js';
export declare class StateSwitch extends StateSwitchEventEmitter implements StateSwitchInterface {
protected readonly _name: string;
protected readonly _options: StateSwitchOptions;
protected _log: Loggable;
protected _activePromise: Promise<void>;
protected _inactivePromise: Promise<void>;
protected _activeResolver: Function;
protected _inactiveResolver: Function;
protected _isActive: boolean;
protected _isPending: boolean;
constructor(_name?: string, _options?: StateSwitchOptions);
name(): string;
version(): string;
/**
* Get the current ON state (3VL).
*/
active(): boolean | Pending;
/**
* Turn on the current state.
* @param state
* `Pending` means we entered the turn on async process
* `true` means we have finished the turn on async process.
*/
active(state: true | Pending): void;
active(state: never): never;
/**
* Get the current OFF state (3VL).
*/
inactive(): boolean | Pending;
/**
* Turn off the current state.
* @param state
* `Pending` means we entered the turn off async process
* `true` means we have finished the turn off async process.
*/
inactive(state: true | Pending): void;
inactive(state: never): never;
/**
* does the state is not stable(in process)?
*/
pending(): boolean;
/**
* Wait the pending state to be stable.
*/
stable(state?: StateType, noCross?: boolean): Promise<void>;
}
//# sourceMappingURL=state-switch.d.ts.map