createSysTimer
Start from API_LEVEL
4.0
. Please refer to API_LEVEL.
A system-level timer that can be registered in device app services and runs regardless of watch screen state.
Type
function createSysTimer(periodic: Periodic, period: Period, callback: Callback, arg?: Arg): Result
Parameters
Periodic
Type | Description |
---|---|
boolean | Whether to create a periodic timer |
Period
Type | Description |
---|---|
number | Timer period (ms). For non-periodic timers, it represents delay duration, 0 means immediate execution |
Callback
Type | Description |
---|---|
(arg?: unknown) => void | Callback function |
Arg
Type | Description |
---|---|
unknown | Parameter passed to the callback function |
Result
Type | Description |
---|---|
number | The ID returned by creating a system timer, used to stop the timer later |
Example
import { createSysTimer } from '@zos/timer'
// Create a non-periodic timer that executes after 5 seconds
const timerId = createSysTimer(
false,
5000,
(param) => {
console.log('timer callback with param:', param)
},
'customParam',
)
// Create a periodic timer that executes every 10 seconds
const intervalId = createSysTimer(true, 10000, () => {
console.log('interval timer callback')
})