Skip to main content

Class: LegacyTimer

A class to create, start, and stop named timers that measure elapsed time in milliseconds.

Deprecated​

Use Timer class instead. To migrate to the Timer class, use Timer.startNew() to create and start a new timer instead of LegacyTimer.start().

Constructors​

new LegacyTimer()​

new LegacyTimer(name): LegacyTimer

Parameters​

• name: string

Returns​

LegacyTimer

Defined in​

m2c2kit/packages/core/src/LegacyTimer.ts:24

Methods​

elapsed()​

static elapsed(name): number

Returns the total time elapsed, in milliseconds, of the timer.

Parameters​

• name: string

The name of the timer whose elapsed duration is requested

Returns​

number

Remarks​

The total time elapsed will include all durations from multiple starts and stops of the timer, if applicable. A timer's elapsed duration can be read while it is in started or stopped state. The method throws an error if a timer with the given name does not exist.

Deprecated​

Use Timer class.

Defined in​

m2c2kit/packages/core/src/LegacyTimer.ts:142


exists()​

static exists(name): boolean

Checks if a timer of the given name exists.

Parameters​

• name: string

The name of the timer to check for existence

Returns​

boolean

boolean

Remarks​

The method checks if there is a timer with the given name.

Deprecated​

Use Timer class.

Defined in​

m2c2kit/packages/core/src/LegacyTimer.ts:205


now()​

static now(): number

Aliases performance.now()

Returns​

number

a DOMHighResTimeStamp

Remarks​

The m2c2kit Timer class is designed to measure elapsed durations after a designated start point for a uniquely named timer. However, if a timestamp based on the time origin is needed, this method can be used.

Deprecated​

Use Timer class.

Defined in​

m2c2kit/packages/core/src/LegacyTimer.ts:41


remove()​

static remove(name): void

Removes a timer.

Parameters​

• name: string

The name of the timer to be removed

Returns​

void

Remarks​

After removal, no additional methods can be used with a timer of the given name, other than to start a new timer with the given name, whose duration will begin at 0 again. The method throws an error if a timer with the given name does not exist.

Deprecated​

Use Timer class.

Defined in​

m2c2kit/packages/core/src/LegacyTimer.ts:170


removeAll()​

static removeAll(): void

Remove all timers.

Returns​

void

Remarks​

This method will remove any timers in a started or stopped state. This method is idempotent; method is safe to call even if there are no timers to remove; no errors are thrown if there are not any timers that can be removed.

Deprecated​

Use Timer class.

Defined in​

m2c2kit/packages/core/src/LegacyTimer.ts:191


restart()​

static restart(name): void

Restarts a timer.

Parameters​

• name: string

The name of the timer to be restarted

Returns​

void

Remarks​

The timer elapsed duration is set to 0 and it starts anew. The method throws an error if a timer with the given name does not exist (if there is not a started or stopped timer with the given name).

Deprecated​

Use Timer class. Use Timer.startNew() to create and start a new timer with the same name.

Defined in​

m2c2kit/packages/core/src/LegacyTimer.ts:117


start()​

static start(name): void

Starts a millisecond-resolution timer based on performance.now().

Parameters​

• name: string

The name of the timer to be started

Returns​

void

Remarks​

The method throws an error if a timer with the given name is already in a started state.

Deprecated​

Use Timer class. Use Timer.startNew() to create and start a new timer or Timer.new() to create a new timer without starting it.

Defined in​

m2c2kit/packages/core/src/LegacyTimer.ts:56


stop()​

static stop(name): void

Stops a timer.

Parameters​

• name: string

The name of the timer to be stopped

Returns​

void

Remarks​

The method throws an error if a timer with the given name is already in a stopped state, or if a timer with the given name has not been started.

Deprecated​

Use Timer class.

Defined in​

m2c2kit/packages/core/src/LegacyTimer.ts:85