Timer Class

Packages > @fluidframework/common-utils > Timer

This class is a thin wrapper over setTimeout and clearTimeout which makes it simpler to keep track of recurring timeouts with the same or similar handlers and timeouts.

Signature:

export declare class Timer implements ITimer 

Implements: ITimer

Constructors

List of constructors for this class
Constructor Modifiers Description
(constructor)(defaultTimeout, defaultHandler, getCurrentTick) Constructs a new instance of the Timer class

Properties

List of properties for this class
Property Modifiers Type Description
hasTimer boolean Returns true if the timer is running.

Methods

List of methods on this class
Method Modifiers Description
clear() Calls clearTimeout on the underlying timeout if running.
restart(ms, handler) Restarts the timer with the new handler and duration. If a new handler is passed, the original handler may never execute. This is a potentially more efficient way to clear and start a new timer.
start(ms, handler) Calls setTimeout and tracks the resulting timeout.

Constructors

Timer.(constructor)

Constructs a new instance of the Timer class

Signature:

constructor(defaultTimeout: number, defaultHandler: () => void, getCurrentTick?: () => number);

Parameters

List of parameters
Parameter Type Description
defaultTimeout number
defaultHandler () => void
getCurrentTick () => number

Properties

hasTimer

Returns true if the timer is running.

Signature:

get hasTimer(): boolean;

Methods

clear

Calls clearTimeout on the underlying timeout if running.

Signature:

clear(): void;

Returns:

void

restart

Restarts the timer with the new handler and duration. If a new handler is passed, the original handler may never execute. This is a potentially more efficient way to clear and start a new timer.

Signature:

restart(ms?: number, handler?: () => void): void;

Parameters

List of parameters
Parameter Type Description
ms number overrides previous or default timeout in ms
handler () => void overrides previous or default handler

Returns:

void

start

Calls setTimeout and tracks the resulting timeout.

Signature:

start(ms?: number, handler?: () => void): void;

Parameters

List of parameters
Parameter Type Description
ms number overrides default timeout in ms
handler () => void overrides default handler

Returns:

void