Skip to content

Commit b1954f2

Browse files
committed
fix bug in reset
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
1 parent f115f6b commit b1954f2

File tree

2 files changed

+3
-14
lines changed

2 files changed

+3
-14
lines changed

src/delay.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,9 @@ impl Delay {
8787

8888
/// Resets this timeout to an new timeout which will fire at the time
8989
/// specified by `at`.
90-
///
91-
/// This method is usable even of this instance of `Delay` has "already
92-
/// fired". That is, if this future has resovled, calling this method means
93-
/// that the future will still re-resolve at the specified instant.
94-
///
95-
/// If `at` is in the past then this future will immediately be resolved
96-
/// (when `poll` is called).
97-
///
98-
/// Note that if any task is currently blocked on this future then that task
99-
/// will be dropped. It is required to call `poll` again after this method
100-
/// has been called to ensure tha ta task is blocked on this future.
10190
#[inline]
102-
pub fn reset(&mut self, dur: Duration) {
103-
self.when = Instant::now() + dur;
91+
pub fn reset(&mut self, at: Instant) {
92+
self.when = at;
10493
if self._reset(self.when).is_err() {
10594
self.state = None
10695
}

tests/smoke.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ async fn reset() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
2424
assert!(i.elapsed() > dur);
2525

2626
let i = Instant::now();
27-
d.reset(dur);
27+
d.reset(Instant::now() + dur);
2828
d.await;
2929
assert!(i.elapsed() > dur);
3030
Ok(())

0 commit comments

Comments
 (0)