@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
69 lines • 1.89 kB
TypeScript
/**
* A watchdog timer that executes a callback function if `kick()` is not called within a specified timeout period.
*/
export class WatchDog {
/**
*
* @param {function} action Callback function to execute on timeout
* @param {*} [actionContext] `this` context for the callback function.
* @constructor
*/
constructor(action: Function, actionContext?: any);
/**
* @private
* @type {number}
*/
private timeoutId;
/**
* Timeout duration in milliseconds
* @type {number}
*/
timeout: number;
/**
*
* @type {number}
* @private
*/
private __timeLastKicked;
/**
* Callback function to be executed when the watchdog timer expires.
* @type {function}
*/
action: Function;
/**
* The context (`this` value) for the {@link action} callback.
* @type {*}
*/
actionContext: any;
/**
* @private
* Executes the callback function and clears the timer. Called when the watchdog timer expires.
*/
private bark;
/**
* Starts the watchdog timer.
* If the timer is already running, this does nothing.
*/
start(): void;
/**
* Stops the watchdog timer.
* If the timer is not running, this does nothing.
*/
stop(): void;
/**
* Checks if the watchdog timer is currently active.
* @returns {boolean} `true` if the timer is running, `false` otherwise.
*/
isActive(): boolean;
/**
* Resets the watchdog timer. Throws an error if the timer is not active.
* @throws {Error} If the watchdog is not active.
*/
kick(): void;
/**
* Sets the timeout duration. Does not start or restart the timer.
* @param {number} delay Timeout duration in milliseconds.
*/
setTimeout(delay: number): void;
}
//# sourceMappingURL=WatchDog.d.ts.map