1use crate::workflow::runtime::timer::{
8 TimerAuthorityWorkflow, recovery_watchdog_identity, require_active,
9};
10use ic_timers::TimerRunResult;
11use std::{future::Future, time::Duration};
12
13pub use crate::workflow::runtime::timer::TimerError;
14
15#[doc(hidden)]
17pub struct TimerApi;
18
19impl TimerApi {
20 #[doc(hidden)]
22 pub fn initialize_nonroot_runtime_required() {
23 TimerAuthorityWorkflow::initialize_nonroot_runtime()
24 .unwrap_or_else(|error| ic_cdk::trap(format!("timer runtime init failed: {error}")));
25 }
26
27 #[doc(hidden)]
29 pub fn initialize_root_runtime_required() {
30 TimerAuthorityWorkflow::initialize_root_runtime()
31 .unwrap_or_else(|error| ic_cdk::trap(format!("timer runtime init failed: {error}")));
32 }
33
34 #[doc(hidden)]
36 pub fn initialize_shared_runtime_required() {
37 TimerAuthorityWorkflow::initialize_shared_runtime()
38 .unwrap_or_else(|error| ic_cdk::trap(format!("timer runtime init failed: {error}")));
39 }
40
41 #[doc(hidden)]
43 pub fn restore_snapshot_suspension(sealed: bool) {
44 TimerAuthorityWorkflow::restore_snapshot_suspension(sealed);
45 }
46
47 #[doc(hidden)]
49 pub fn require_root_authority_snapshot_resumable() -> Result<(), TimerError> {
50 TimerAuthorityWorkflow::require_root_resumable()
51 }
52
53 #[doc(hidden)]
55 pub fn require_active() -> Result<(), TimerError> {
56 require_active()
57 }
58
59 #[doc(hidden)]
61 pub fn recovery_watchdog_identity() -> Result<ic_timers::TimerIdentity, TimerError> {
62 recovery_watchdog_identity()
63 }
64
65 #[doc(hidden)]
67 #[must_use]
68 pub fn recover_expired_async_jobs(now_ns: u64) -> u64 {
69 TimerAuthorityWorkflow::recover_expired_async_jobs(now_ns)
70 }
71
72 #[doc(hidden)]
74 pub fn defer_lifecycle_required(
75 delay: Duration,
76 label: impl Into<String>,
77 task: impl Future<Output = ()> + 'static,
78 ) {
79 TimerAuthorityWorkflow::defer_lifecycle_once(delay, label, task)
80 .unwrap_or_else(|error| ic_cdk::trap(format!("lifecycle timer rejected: {error}")));
81 }
82
83 #[doc(hidden)]
85 pub fn defer_lifecycle_result_required(
86 delay: Duration,
87 label: impl Into<String>,
88 task: impl Future<Output = TimerRunResult> + 'static,
89 ) {
90 TimerAuthorityWorkflow::defer_lifecycle_result_once(delay, label, task)
91 .unwrap_or_else(|error| ic_cdk::trap(format!("lifecycle timer rejected: {error}")));
92 }
93}