Skip to main content

Timer

Reference for mo:core/Timer in the core library.

Timers schedule ordinary async callbacks. Any state reasoning inside the job must follow the same await/interleaving model as other actor methods.

Import

mo:core/Timer

Status

  • Runtime module

Public API

Types

  • TimerId

Functions

setTimer<system>(duration : Time.Duration, job : () -> async ()) : TimerId

Schedules job once after duration and returns its timer id.

Use when: a canister needs delayed asynchronous work. The callback uses ordinary async execution, so review the async interleaving rules before depending on state across awaits.

recurringTimer<system>(duration : Time.Duration, job : () -> async ()) : TimerId

Schedules an asynchronous timer job and returns its timer id.

Use when: a canister needs repeated asynchronous work.

cancelTimer(id : TimerId)

Cancels a previously scheduled timer id.

Use when: timer ownership or state changes make a scheduled job obsolete.

Summary

  • Runtime module under mo:core/Timer.
  • Exposes 3 public functions.