目录

Timer

setInterval

setInterval(function callback, number delay, any rest): string

Sets a timer to repeatedly execute the callback function at an interval specified by delay.

An atomic service has a mechanism for switching to the background and being frozen. When an atomic service calls an API, if the background permission is not applied for, the execution will stop when the atomic service is switched to the background.

Since: 1.0.0

Parameters

Parameter Type Mandatory Description
callback function Yes Callback used to return the result.
delay number Yes

Interval at which the callback is executed, in ms.

It is a string that supports numeric values. If it is left empty or if a non-numeric value is passed, it defaults to 0.

rest any No Additional parameters such as param1 and param2, which are passed to the callback as arguments.

Returns

Parameter Type Description
intervalID string Timer ID.

Example:

// Create a timer.
const intervalID = setInterval((params1, params2) => {
  console.info('setInterval success', params1, params2);
}, 3000, 'param1', 'param2');
// Print the timer ID.
console.info('intervalID: ', intervalID);

clearInterval

clearInterval(string intervalID)

Cancels the timer set by calling setInterval.

Since: 1.0.0

Parameters

Parameter Type Mandatory Description
intervalID string Yes ID of the timer to cancel.

Example:

// Create a timer.
const intervalID = setInterval((params1, params2) => {
  console.info('setInterval success', params1, params2);
}, 3000, 'param1', 'param2');
// Cancel the created timer.
clearInterval(intervalID);

setTimeout

setTimeout(function callback, number delay, any rest): string

Sets a timer that is executed only once. After an interval specified by delay, the callback function is executed.

An atomic service has a mechanism for switching to the background and being frozen. When an atomic service calls an API, if the background permission is not applied for, the execution will stop when the atomic service is switched to the background.

Since: 1.0.0

Parameters

Parameter Type Mandatory Description
callback function Yes Callback used to return the result.
delay number Yes

Interval at which the callback is executed, in ms.

It is a string that supports numeric values. If it is left empty or if a non-numeric value is passed, it defaults to 0.

rest any No Additional parameters such as param1 and param2, which are passed to the callback as arguments.

Returns

Parameter Type Description
timeoutID string Timer ID.

Example:

// Create a timer.
const timeoutID = setTimeout((params1, params2) => {
  console.info('setTimeout success', params1, params2);
}, 3000, 'param1', 'param2');
// Print the timer ID.
console.info('timeoutID: ', timeoutID);

clearTimeout

clearTimeout(string timeoutID)

Cancels the timer set by calling setTimeout.

Since: 1.0.0

Parameters

Parameter Type Mandatory Description
timeoutID string Yes ID of the timer to cancel.

Example:

// Create a timer.
const timeoutID = setTimeout((params1, params2) => {
  console.info('setTimeout success', params1, params2);
}, 3000, 'param1', 'param2');
// Cancel the created timer.
clearTimeout(timeoutID);