Canvas Toolkit
← Class index

CTimer

Core · extends CObject

Provides single-shot and repeating timer functionality.

Module core/CTimer.js. This class is available through the browser modules in the download.

Declared members

readonly timeout: CSignal<[]>;

Emitted when the timer interval expires.

constructor(parent?: CObject | null);

Creates a timer. @param parent Parent object, or `null` for no parent.

interval(): number;

Returns the timer interval in milliseconds. @returns Timer interval in milliseconds.

setInterval(interval: number): void;

Sets the timer interval. An active timer is restarted with the new interval. @param interval Interval in milliseconds. Negative values are clamped to zero.

isSingleShot(): boolean;

Returns whether the timer fires only once. @returns `true` for a single-shot timer; otherwise `false`.

setSingleShot(singleShot: boolean): void;

Sets whether the timer fires only once. @param singleShot `true` for single-shot operation; `false` for repeating operation.

isActive(): boolean;

Returns whether the timer is currently active. @returns `true` if the timer is active.

start(interval?: number): void;

Starts or restarts the timer. @param interval Optional interval in milliseconds to use before starting.

stop(): void;

Stops the timer.

remainingTime(): number;

Returns the approximate time remaining until the next timeout. @returns Remaining milliseconds, or `-1` if the timer is inactive.

static singleShot(interval: number, callback: () => void): void;

Schedules a callback to run once after the specified interval. @param interval Delay in milliseconds. Negative values are clamped to zero. @param callback Function to invoke after the delay.

destroy(): void;

Stops scheduled callbacks before releasing child objects.