Skip to content

Commit 616f421

Browse files
Add back Timer::at
1 parent afabed9 commit 616f421

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/lib.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ pub struct Timer {
6868
}
6969

7070
impl Timer {
71+
/// Creates a timer that expires at the specified instant in time.
72+
pub fn at(when: Instant) -> Timer {
73+
Timer {
74+
id_and_waker: None,
75+
when,
76+
}
77+
}
78+
7179
/// Creates a timer that expires after the given duration of time.
7280
///
7381
/// # Examples
@@ -81,11 +89,8 @@ impl Timer {
8189
/// # });
8290
/// ```
8391
pub fn new(dur: Duration) -> Timer {
84-
Timer {
85-
id_and_waker: None,
86-
when: Instant::now() + dur,
87-
}
88-
}
92+
Timer::at(Instant::now() + dur)
93+
}
8994

9095
/// Resets the timer to expire after the new duration of time.
9196
///

0 commit comments

Comments
 (0)