LiveEventTimer class

Periodically broadcasts an event to listening LiveEventTarget instances.

Constructors

LiveEventTimer<T>(LiveEventSource<T>, () => T, number, boolean)

Creates a new LiveEventTimer instance. @param eventSource Event source that will be used to emit events. @param createEvent Function used to construct an event to send. This will be called at regular intervals prior to sending an event. @param delay Period to delay for in milliseconds. @param repeat Optional. If true the timer will repeat once start` is called, otherwise a single event will be sent after the delay. Defaults to false.

Properties

delay

The rate at which the events are sent in milliseconds.

isRunning

Returns true if the timer is currently running.

repeat

If true the event will automatically repeat at an interval specified by the delay.

Methods

sendEvent()

Immediately sends an event.

start()

Starts the timer.

stop()

Stops the timer if its running.

Constructor Details

LiveEventTimer<T>(LiveEventSource<T>, () => T, number, boolean)

Creates a new LiveEventTimer instance. @param eventSource Event source that will be used to emit events. @param createEvent Function used to construct an event to send. This will be called at regular intervals prior to sending an event. @param delay Period to delay for in milliseconds. @param repeat Optional. If true the timer will repeat once start` is called, otherwise a single event will be sent after the delay. Defaults to false.

new LiveEventTimer(eventSource: LiveEventSource<T>, createEvent: () => T, delay: number, repeat?: boolean)

Parameters

eventSource

LiveEventSource<T>

createEvent

() => T

delay

number

repeat

boolean

Property Details

delay

The rate at which the events are sent in milliseconds.

number delay

Property Value

number

isRunning

Returns true if the timer is currently running.

boolean isRunning

Property Value

boolean

repeat

If true the event will automatically repeat at an interval specified by the delay.

repeat: boolean

Property Value

boolean

Method Details

sendEvent()

Immediately sends an event.

function sendEvent(): Promise<ILiveEvent<T>>

Returns

Promise<ILiveEvent<T>>

Remarks

The createEvent callback to construct the event is called but does not impact any pending timeouts. Call start after calling sendEvent if you'd like to skip the next timer interval.

start()

Starts the timer.

function start()

Remarks

If the timer is running it will be stooped and then re-started with a new delay.

stop()

Stops the timer if its running.

function stop()