docs.rodeo

MDN Web Docs mirror

WorkerGlobalScope: setTimeout() method

{{APIRef("HTML DOM")}} {{AvailableInWorkers("worker")}} 

The setTimeout() method of the {{domxref("WorkerGlobalScope")}}  interface sets a timer which executes a function or specified piece of code once the timer expires.

Syntax

setTimeout(code)
setTimeout(code, delay)

setTimeout(functionRef)
setTimeout(functionRef, delay)
setTimeout(functionRef, delay, param1)
setTimeout(functionRef, delay, param1, param2)
setTimeout(functionRef, delay, param1, param2, /* …, */ paramN)

Parameters

Return value

The setTimeout() method returns a positive integer (typically within the range of 1 to 2,147,483,647) that uniquely identifies the timer created by the call. This identifier, often referred to as a “timeout ID”, can be passed to {{domxref("Window.clearTimeout","clearTimeout()")}}  to cancel the timer.

Within the same global environment (e.g., a specific window or worker) the timeout ID is guaranteed not to be reused for any new timer as long as the original timer remains active. However, separate global environments maintain their own independent pools of timer IDs.

Description

See {{domxref("Window.setTimeout()")}}  for detailed descriptions.

Examples

See {{domxref("Window.setTimeout()")}}  for examples.

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN