UNPKG

@bugtamer/async-status

Version:
94 lines 2.94 kB
declare enum State { /** Never executed */ noCalls = 0, /** Already running */ started = 1, /** Successfully finished */ done = 2, /** Failed execution */ aborted = 3 } /** * Async process status management. * @license MIT * @author Bugtamer */ export declare class AsyncStatus { static readonly UNDEFINED_TIME = -1; /** * Flag the process as execution in progress. * @throws an error when `start()` is called and the process was already running. * @throws an error when `start()` is executed more than `Number.MAX_SAFE_INTEGER`: * 9007199254740991 times. */ start(): void; /** * - Flag the process as successfully completed. * @throws an error when `end()` is called and the process was not already running. */ end(): void; /** * - Flag the process as unexpectedly ended with an error. * @throws an error when `abort()` is called and the process was not already running. */ abort(): void; /** * Set all stats to zero. */ resetAttemptStats(): void; /** * The process is not already running: * - never executed * - successfully finished * - unsuccessfully finished */ get isIdle(): boolean; /** * The process is already on execution. */ get isOngoing(): boolean; /** * The process outcome was successful. */ get wasSuccessful(): boolean; /** * The process outcome was unsuccessful. */ get wasFailed(): boolean; /** * Time elapsed in milliseconds between the last call to `start()` * and a call to `end()`, `abort()` or current time if neither of them were called. * `-1` is returned when `start()` has never been called. */ get elapsedTime(): number; /** * Number of calls to `start()`. */ get attempts(): number; /** * Number of calls to `end()`. */ get successfulAttempts(): number; /** * Number of calls to `abort()`. */ get failedAttempts(): number; /** * @returns milliseconds */ protected _currentTime(): number; protected _forbiddenStateGuard(isAnIllegalState: boolean, errorMessage: string): void; protected _overflowGuard(currentCount: number): void; protected _attemptCount: number; protected _successfulAttemptCount: number; protected _failedAttemptCount: number; protected _initialTime: number; protected _finalTime: number; protected _status: State; protected static readonly startErrorMessage = "'start()' cannot be called in 'started' state."; protected static readonly endErrorMessage = "'end()' cannot be called in 'idle' state."; protected static readonly abortErrorMessage = "'abort()' cannot be called in 'idle' state."; protected static readonly overflowErrorMessage = "Overflow error."; } export {}; //# sourceMappingURL=async-status.d.ts.map