Skip to content

Commit c9ead9e

Browse files
committed
feat(Timer): Add return from OneShot Timer::wait()
Return a TimerBuilder<OneShot, Armed, ...>
1 parent 720ea0e commit c9ead9e

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/timer.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,11 @@ impl<Type, Clock: crate::Clock, Dur: Duration> Timer<Type, Running, Clock, Dur>
135135

136136
impl<Clock: crate::Clock, Dur: Duration> Timer<OneShot, Running, Clock, Dur> {
137137
/// Block until the timer has expired
138-
pub fn wait(self) {
138+
pub fn wait(self) -> Timer<OneShot, Armed, Clock, Dur> {
139139
// since the timer is running, _is_expired() will return a value
140140
while !self._is_expired() {}
141+
142+
Timer::<param::None, param::None, Clock, Dur>::new().set_duration(self.duration.unwrap())
141143
}
142144

143145
/// Check whether the timer has expired
@@ -224,12 +226,20 @@ mod test {
224226
init_start_time();
225227

226228
// WHEN blocking on a timer
227-
Clock::new_timer().set_duration(1.seconds()).start().wait();
229+
let timer = Clock::new_timer().set_duration(1.seconds()).start().wait();
228230

229231
// THEN the block occurs for _at least_ the given duration
230232
unsafe {
231233
assert!(Seconds::<i32>::try_from(START.unwrap().elapsed()).unwrap() >= 1.seconds());
232234
}
235+
236+
// WHEN blocking on a timer
237+
timer.start().wait();
238+
239+
// THEN the block occurs for _at least_ the given duration
240+
unsafe {
241+
assert!(Seconds::<i32>::try_from(START.unwrap().elapsed()).unwrap() >= 2.seconds());
242+
}
233243
}
234244

235245
#[test]

0 commit comments

Comments
 (0)