aboutsummaryrefslogtreecommitdiff
path: root/embassy-time/src
diff options
context:
space:
mode:
authorAdam Greig <[email protected]>2023-10-15 00:31:32 +0100
committerAdam Greig <[email protected]>2023-10-15 00:47:55 +0100
commitc8fdbe19f91a02b86008c73ba021d8e7d2f4986b (patch)
tree5b40e4bbb840b94e4f18c7ddf987b1168d361ca0 /embassy-time/src
parent2e50bf667a02ac3cb2b48dd61ca394b589ac20df (diff)
time: Add convenience methods for Timer::after_secs/millis/micros/ticks
Diffstat (limited to 'embassy-time/src')
-rw-r--r--embassy-time/src/timer.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/embassy-time/src/timer.rs b/embassy-time/src/timer.rs
index 07ddf473f..ee2423daf 100644
--- a/embassy-time/src/timer.rs
+++ b/embassy-time/src/timer.rs
@@ -64,6 +64,42 @@ impl Timer {
64 yielded_once: false, 64 yielded_once: false,
65 } 65 }
66 } 66 }
67
68 /// Expire after the specified number of ticks.
69 ///
70 /// This method is a convenience wrapper for calling `Timer::after(Duration::from_ticks())`.
71 /// For more details, refer to [`Timer::after()`] and [`Duration::from_ticks()`].
72 #[inline]
73 pub fn after_ticks(ticks: u64) -> Self {
74 Self::after(Duration::from_ticks(ticks))
75 }
76
77 /// Expire after the specified number of microseconds.
78 ///
79 /// This method is a convenience wrapper for calling `Timer::after(Duration::from_micros())`.
80 /// For more details, refer to [`Timer::after()`] and [`Duration::from_micros()`].
81 #[inline]
82 pub fn after_micros(micros: u64) -> Self {
83 Self::after(Duration::from_micros(micros))
84 }
85
86 /// Expire after the specified number of milliseconds.
87 ///
88 /// This method is a convenience wrapper for calling `Timer::after(Duration::from_millis())`.
89 /// For more details, refer to [`Timer::after`] and [`Duration::from_millis()`].
90 #[inline]
91 pub fn after_millis(millis: u64) -> Self {
92 Self::after(Duration::from_millis(millis))
93 }
94
95 /// Expire after the specified number of seconds.
96 ///
97 /// This method is a convenience wrapper for calling `Timer::after(Duration::from_secs())`.
98 /// For more details, refer to [`Timer::after`] and [`Duration::from_secs()`].
99 #[inline]
100 pub fn after_secs(secs: u64) -> Self {
101 Self::after(Duration::from_secs(secs))
102 }
67} 103}
68 104
69impl Unpin for Timer {} 105impl Unpin for Timer {}