Link Search Menu Expand Document

Timer API

Imperative thread offers basic timer control using Libertas_Wait or Libertas_WaitUntil.

Reactive model offers callback-based timer control.

Timer Object

LibertasTimer

LibertasTimer represents a timer object, which is an opaque object.

LibertasTimerCallback

LibertasTimerCallback defines a callback function.

type LibertasTimerCallback = (tag: any, timer: LibertasTimer) => void;

Scheduling, Rescheduling, Cancel

Libertas_TimerNew

Libertas_TimerNew creates a timer with a timeout in milliseconds, a callback function, and an optional tag value.

function Libertas_TimerNew(timeout: number, func: LibertasTimerCallback, tag?: any): LibertasTimer;

Note that LibertasTimer is always a one-off. The callback function will be triggered once.

To make the timer repetitive, Thing-App shall call Libertas_TimerUpdate in the callback function to “re-arm” the timer.

Libertas_TimerUpdate

function Libertas_TimerUpdate(timer: LibertasTimer, timeout: number, func?: LibertasTimerCallback, tag?: any): void;

Note, Libertas_TimerUpdate is also used to reschedule the timer at any time.

Libertas_TimerCancel

function Libertas_TimerCancel(timer: LibertasTimer): void;

Libertas_TimerCancel is used to cancel the timer at any time.

If the timer is canceled or triggered without “re-arm,” the timer will be automatically garbage collected.