Skip to content

Commit aa0dee8

Browse files
author
Stjepan Glavina
authored
Merge pull request async-rs#7 from Matthias-Fauconneau/master
Add back Timer::at
2 parents 5eaf7c8 + 616f421 commit aa0dee8

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
@@ -114,6 +114,14 @@ pub struct Timer {
114114
}
115115

116116
impl Timer {
117+
/// Creates a timer that expires at the specified instant in time.
118+
pub fn at(when: Instant) -> Timer {
119+
Timer {
120+
id_and_waker: None,
121+
when,
122+
}
123+
}
124+
117125
/// Creates a timer that expires after the given duration of time.
118126
///
119127
/// # Examples
@@ -127,11 +135,8 @@ impl Timer {
127135
/// # });
128136
/// ```
129137
pub fn new(dur: Duration) -> Timer {
130-
Timer {
131-
id_and_waker: None,
132-
when: Instant::now() + dur,
133-
}
134-
}
138+
Timer::at(Instant::now() + dur)
139+
}
135140

136141
/// Resets the timer to expire after the new duration of time.
137142
///

0 commit comments

Comments
 (0)