All Products
Search
Document Center

Mobile Platform as a Service:Timer

Last Updated:Nov 26, 2025

The card has the ability to delay execution and timing execution. The methods of delayed execution and timed execution are described below, respectively.

setTimeout

This method allows a function to be called or a section of code to be executed after a period of time.

This use case indicates that the arrow function is executed after 1 second.

setTimeout(() => {
  console.info("setTimeout");
}, 1000);

setInterval

This method allows a function to be called or a code segment to be executed repeatedly at the same time intervals.

This use case indicates that the arrow function is executed every 1 second.

setInterval(() => {
  console.info("setTimeout");
}, 1000);

Clear timer

For setTimeout, if you need to cancel the timer before the function is triggered, you need to manually call clearTimeout to cancel the timer. If the trigger is triggered after the function is executed, you do not need to manually clear it.

For setInterval, you must call clearInterval to cancel the timer if canceled. Otherwise, a memory leak occurs.

Example:

// setTimeout
var timer1 = setTimeout(() => {
  console.info("setTimeout");
}, 1000);

clearTimeout(timer1);

// setInterval 
var timer2 = setInterval(() => {
  console.info("setInterval");
}, 1000);

clearInterval(timer2);

Example code

Click here detailTimer.zip for the complete example code.