canic_core/macros/timer.rs
1//! Perf-instrumented timer helpers that auto-label with module + function name.
2//!
3//! These macros wrap [`TimerOps`](crate::ops::timer::TimerOps) so callers can
4//! schedule work without manually threading labels. Labels are constructed
5//! as `module_path!()::function_name`.
6
7///
8/// timer
9/// Schedule a one-shot timer with an auto-generated label.
10///
11/// # Examples
12/// - `timer!(Duration::from_secs(5), do_cleanup);`
13/// - `timer!(Duration::ZERO, my_task, arg1, arg2);`
14///
15#[macro_export]
16macro_rules! timer {
17 ($delay:expr, $func:path $(, $($args:tt)*)? ) => {{
18 let label = concat!(module_path!(), "::", stringify!($func));
19 $crate::ops::timer::TimerOps::set($delay, label, $func($($($args)*)?))
20 }};
21}
22
23///
24/// timer_interval
25/// Schedule a repeating timer with an auto-generate label.
26///
27/// # Examples
28/// - `timer_interval!(Duration::from_secs(60), heartbeat);`
29/// - `timer_interval!(Duration::from_secs(10), tick, state.clone());`
30///
31#[macro_export]
32macro_rules! timer_interval {
33 ($interval:expr, $func:path $(, $($args:tt)*)? ) => {{
34 let label = concat!(module_path!(), "::", stringify!($func));
35 $crate::ops::timer::TimerOps::set_interval($interval, label, move || $func($($($args)*)?))
36 }};
37}