Skip to main content
Version: v3+

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

TypeDescription
booleanWhether to create a periodic timer

Period

TypeDescription
numberTimer period (ms). For non-periodic timers, it represents delay duration, 0 means immediate execution

Callback

TypeDescription
(arg?: unknown) => voidCallback function

Arg

TypeDescription
unknownParameter passed to the callback function

Result

TypeDescription
numberThe 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')
})