Skip to content

Timer

Overview

Timer so that other modules can run timing related code through the simulation's requestAnimationFrame. Use its Emitter interface for adding/removing listeners.

@author Sam Reid (PhET Interactive Simulations)

Class Timer

import { Timer } from 'scenerystack/axon';

Instance Methods

setTimeout( listener : () => void, timeout : number ) : TimerListener

Adds a listener to be called back once after the specified time in milliseconds @param listener - called with no arguments @param timeout in milliseconds @returns an internally-wrapped listener which can be removed with clearTimeout

clearTimeout( listener : TimerListener )

Clear a scheduled timeout. If there was no timeout, nothing is done.

setInterval( listener : () => void, interval : number ) : TimerListener

Adds a listener to be called at specified intervals (in milliseconds) @param listener - called with no arguments @param interval - in milliseconds @returns an internally-wrapped listener which can be removed with clearInterval

clearInterval( listener : TimerListener )

Clear a scheduled interval. If there was no interval, nothing is done.

runOnNextTick( listener : () => void )

Run a callback on the next frame. This method is largely for clarity.

Type TimerListener

import type { TimerListener } from 'scenerystack/axon';

( dt: number ) => void

Source Code

See the source for Timer.ts in the axon repository.