<aside> 🔌 The timers API exposes a global API for scheduling functions to be called at some future period of time.

</aside>

Getting Started


Functions like setTimeout and setInterval are not part of the V8 engine so we have implemented them in this module.

Example


var count = 0
setInterval(() => {
	console.log('Counting', count)
	count++
}, 1000)

Functions


setImmediate


setImmediate(
	callback: () => void, ...args: any[]
)

Schedules the "immediate" execution of the callback.

PARAMETERS

callback: () => void

The function to execute.

...args: any[]

Arguments to pass to the callback.

RETURNS

number

The identifier for the immediate timer.


setInterval

setInterval(
	callback: () => void, delay?: number, ...args: any[]
)

Schedules repeated execution of callback every delay milliseconds.

PARAMETERS

callback: () => void

The function to execute.

delay?: number

The number of milliseconds to wait between executions.

...args: any[]

Arguments to pass to the callback.

RETURNS

number

The identifier for the interval timer.


setTimeout

setTimeout(
	callback: () => void, delay?: number, ...args: any[]
)

Schedules execution of a one-time callback after delay milliseconds.

PARAMETERS

callback: () => void

The function to execute.

delay?: number

The number of milliseconds to wait before execution.

...args: any[]

Arguments to pass to the callback.


RETURNS

number

The identifier for the timeout timer.


clearImmediate

clearImmediate(
	id: number
)

Cancels the immediate execution.

PARAMETERS

id: number

The identifier of the immediate timer to cancel.

RETURNS

void


clearInterval

clearInterval(
	id: number
)

Cancels the interval execution.

PARAMETERS

id: number

The identifier of the interval timer to cancel.

RETURNS

void


clearTimeout

clearTimeout(
	id: number
)

Cancels the timeout execution.

PARAMETERS

id: number

The identifier of the timeout timer to cancel.

RETURNS

void