/** * * Promise-aware recurring task timer for use by framework and applications. * * This object is designed to be robust across failing tasks, and never to re-run the task * simultaneously, unless in the case of a timeout. Callers can optionally specify the duration * of asynchronous tasks by returning a Promise from runFn. * * This object seeks to mirror the API and semantics of `Timer.groovy` from Hoist Core as closely * as possible. However, there are important differences due to the synchronous nature of * javascript. In particular, there is no support for `runImmediatelyAndBlock`, and the `timeout` * argument will not be able to interrupt synchronous activity of the runFn. * * All public properties should be considered read-only. * See `setInterval()` to change the interval of this Timer dynamically. */ export declare class Timer { static _timers: Timer[]; static MIN_INTERVAL_MS: number; runFn: () => any; interval: number | (() => number); timeout: number | (() => number); delay: number | boolean; scope: any; intervalUnits: number; timeoutUnits: number; cancelled: boolean; isRunning: boolean; lastRun: Date; private warnedIntervals; /** Create a new Timer. */ static create({ runFn, interval, timeout, intervalUnits, timeoutUnits, delay, scope }: TimerSpec): Timer; /** * Permanently cancel *all* running timers. * * This method is intended for framework use only. * It is a one-way operation, intended for permanently halting app activity before sleeping. */ static cancelAll(): void; /** Permanently cancel this timer. */ cancel(): void; /** * Change the interval of this timer (any value `<=0` will pause the timer). */ setInterval(interval: number | string): void; constructor(args: any); private cancelInternal; private heartbeatAsync; private doRunAsync; private internalRunFn; private parseDynamicVal; private parseDelay; private get intervalMs(); private get timeoutMs(); destroy(): void; } /** * Configuration for a {@link Timer} - a managed interval that runs a function repeatedly * with configurable delay, timeout, and app-config-driven intervals. * * @see Timer */ export interface TimerSpec { /** * Function to run. * For async activity, return a promise to allow timer to prevent overlapping runs. */ runFn: () => any; /** * Interval between runs, in milliseconds. * If a number and `<=0` job will not run. * If a function, will be re-evaluated after every timer run. * If a string, will be interpreted as an AppConfig key and looked up to determine the value. */ interval: number | (() => number) | string; /** * Timeout for action in milliseconds. * Like interval, this value may also be specified as a function or a config key. * Set to null for no timeout. */ timeout?: number | (() => number) | string; /** Units that the interval arg is specified in. Default is ms. */ intervalUnits?: number; /** Units that the timeout arg is specified in. Default is ms. */ timeoutUnits?: number; /** * Initial delay, in milliseconds. * If specified as true, the value of the delay will be the same as interval. Default to false. */ delay?: number | boolean; /** Scope to run runFn in. */ scope?: any; }