Skip to content

Update periodic_tasks example to ic-cdk-timers v1.0.0 API #1314

@marc0olo

Description

@marc0olo

Problem

The rust/periodic_tasks/timer example uses ic-cdk-timers = "0.6" and the old closure-based API. The ic-cdk-timers v1.0.0 release (2025-11-13) introduced breaking changes to function signatures.

What needs updating

Dependencies (timer/Cargo.toml)

  • ic-cdk 0.120.19
  • ic-cdk-macros 0.8 → current
  • ic-cdk-timers 0.61.0

Code (timer/src/lib.rs)

set_timer_interval signature changed — now takes FnMut() -> impl Future instead of FnOnce():

// Old (line 71):
let timer_id = ic_cdk_timers::set_timer_interval(secs, periodic_task);

// New:
let timer_id = ic_cdk_timers::set_timer_interval(secs, || async { periodic_task() });

ic_cdk::spawn() comment is obsolete (lines 75-77) — set_timer now takes futures directly, no spawn wrapper needed.

dfx references in doc comments (lines 53, 65, 82, 96) — dfx is deprecated, should use icp CLI.

Heartbeat example (heartbeat/Cargo.toml)

  • Same outdated ic-cdk/ic-cdk-macros versions

Project-level

  • dfx.json at project root — should be migrated to icp.yaml

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions