Skip to main content

Intervals (Time Events)

Interval events (timing functions in JavaScript) allow the user to periodically run API and DB queries. You can configure these by using the setInterval and clearInterval functions.

How To Use The SetInterval & ClearInterval Functions To Auto-Update Widgets

setInterval()

setInterval() executes a callback function with a fixed time interval between the calls.

Signature

setInterval(callbackFunction: Function, interval: number, id?: string, args?: any)

Arguments

Argument NameDescription
callbackFunctionA function to be called repeatedly every interval number of milliseconds.
intervalThe number of milliseconds to wait between calls of the callbackFunction.
idA custom string name that can be used to refer to this interval timer. When making a clearInterval() call, use this name as the id argument to clearInterval.

Example

setInterval(() => { Query1.run() }, 10000, "myTimer");

clearInterval()

clearInterval() stops a repeating callback that was started with the setInterval method.

Signature

clearInterval(id: string)

Arguments

Argument NameDescription
idThe id string of the timer to be cleared. This should match the id argument of the setInterval() call that you are trying to stop.

Example

clearInterval("myTimer");

setTimeout()

setTimeout() executes a piece of code once after a specified amount of time has passed.

Signature

setTimeout(callbackFunction: Function, delay: number)

Arguments

Argument NameDescription
callbackFunctionA function to be called once after a delay number of milliseconds have passed.
delayThe number of milliseconds to wait before calling the callbackFunction.

Example

setTimeout(() => { showAlert("5 seconds have passed") }, 5000);