Periodically executes a callback function.

Timer uses JavaScript's requestAnimationFrame to repeatedly schedule the callback. On older browsers the setTimeout function is used, see setLegacy.

If the period is left at the default value of zero, then the callback fires at the rate determined by requestAnimationFrame, usually 60 frames per second.

If the period is set to a slower frame rate than 60 fps then Timer skips firing the callback occasionally to achieve that slower rate of firing.

See BlankSlateApp for example code using a Timer.

Constructors

  • Parameters

    • Optional opt_legacy: boolean

      turns on legacy mode, which uses the browser method setTimeout instead of requestAnimationFrame; default is false

    • Optional opt_sysClock: SystemClock

      a SystemClock to use for this Clock (optional)

    Returns Timer

Properties

callBack_: null | (() => void) = null

the callback function

Type declaration

    • (): void
    • Returns void

delta_: number = 0

How late the last callback was.

fired_sys_: number = NaN

When last callback happened

firing_: boolean = false

Whether the Timer should be executing the callBacks.

legacy_: boolean

Whether running under a modern or old browser.

period_: number = 0

period between callbacks, in seconds

timeoutID_?: number = undefined

the ID used to cancel the callback

Methods

  • Returns whether the legacy timer is being used.

    Returns boolean

    whether the legacy timer is being used

  • Returns the default time period between callbacks in seconds of system clock time.

    Returns number

    the number of seconds between successive callbacks

  • Whether the chain of callbacks is firing (executing)

    Returns boolean

  • Sets the callback function to be executed periodically, and calls stopFiring to stop the Timer and any previously scheduled callback.

    Parameters

    • callBack: null | (() => void)

      the function to be called periodically; can be null

    Returns void

  • Sets whether to use the legacy timer.

    Parameters

    • legacy: boolean

      whether to use the legacy timer

    Returns void

  • Sets the default time period between callback execution in seconds of system clock time. A setting of zero means to use the default period which is usually 60 frames per second.

    Parameters

    • period: number

      the number of seconds between successive callbacks, or zero to use the default period (usually 60 frames per second).

    Returns void

    Throws

    if period is negative

  • Immediately fires the callback and schedules the callback to fire repeatedly in the future.

    Returns void

  • Stops the Timer from firing callbacks and cancels the next scheduled callback.

    Returns void

  • the callback function, it must reschedule itself to maintain 'chain of callbacks'

    Returns void

Generated using TypeDoc