Skip to main content

dex_sdk/
timer.rs

1// Copyright (c) 2026 Super Durable, Inc.
2//
3// Licensed under the Sustainable Use License 1.0.
4// You may not use this file except in compliance with the License.
5// See the LICENSE file in the repository root.
6//
7// SPDX-License-Identifier: LicenseRef-Sustainable-Use-1.0
8
9use std::time::Duration;
10
11use crate::Condition;
12
13/// Creates durable timer conditions for Step waits.
14pub struct Timer;
15
16impl Timer {
17    /// Returns a condition that becomes true after `duration` elapses.
18    ///
19    /// Timer duration is measured by Dex workflow time and survives Worker restarts.
20    pub fn by_duration(duration: Duration) -> Condition {
21        Condition::timer(duration)
22    }
23}
24
25#[derive(Clone, Debug, Eq, PartialEq)]
26/// Selects one timer from a Step execution for [`crate::Client::skip_timer`].
27pub enum TimerId {
28    /// Targets the condition carrying this explicit condition ID.
29    ConditionId(String),
30    /// Targets the zero-based timer-condition index within the wait result.
31    ConditionIndex(usize),
32}
33
34impl TimerId {
35    /// Selects a timer by the ID assigned with [`Condition::with_id`].
36    pub fn by_condition_id(id: impl Into<String>) -> Self {
37        Self::ConditionId(id.into())
38    }
39
40    /// Selects a timer by its zero-based condition index.
41    pub fn by_condition_index(index: usize) -> Self {
42        Self::ConditionIndex(index)
43    }
44}