dfinity / dfinity/examples

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

Open
#1,314 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
613
Forks
434
Avg merge
8h 28m
Merged PRs (30d)
9

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with rust/periodic_tasks/timer/Cargo.toml and src/lib.rs, then inspect heartbeat/Cargo.toml and the project-root dfx.json. Compare the timer code with the ic-cdk-timers v1.0.0 changelog and verify the documented API and CLI references. Done means both examples use the requested dependency versions and API, doc comments use icp, and the project configuration is migrated to icp.yaml.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend, build-system
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.