@@ -25,7 +25,6 @@ use crate::{ScheduledTimer, TimerHandle};
2525/// at.
2626pub struct Delay {
2727 state : Option < Arc < Node < ScheduledTimer > > > ,
28- when : Instant ,
2928}
3029
3130impl Delay {
@@ -38,12 +37,6 @@ impl Delay {
3837 Delay :: new_handle ( Instant :: now ( ) + dur, Default :: default ( ) )
3938 }
4039
41- /// Return the `Instant` when this delay will fire.
42- #[ inline]
43- pub fn when ( & self ) -> Instant {
44- self . when
45- }
46-
4740 /// Creates a new future which will fire at the time specified by `at`.
4841 ///
4942 /// The returned instance of `Delay` will be bound to the timer specified by
@@ -54,7 +47,6 @@ impl Delay {
5447 None => {
5548 return Delay {
5649 state : None ,
57- when : at,
5850 }
5951 }
6052 } ;
@@ -72,28 +64,25 @@ impl Delay {
7264 if inner. list . push ( & state) . is_err ( ) {
7365 return Delay {
7466 state : None ,
75- when : at,
7667 } ;
7768 }
7869
7970 inner. waker . wake ( ) ;
8071 Delay {
8172 state : Some ( state) ,
82- when : at,
8373 }
8474 }
8575
8676 /// Resets this timeout to an new timeout which will fire at the time
8777 /// specified by `at`.
8878 #[ inline]
89- pub fn reset ( & mut self , at : Instant ) {
90- self . when = at;
91- if self . _reset ( self . when ) . is_err ( ) {
79+ pub fn reset ( & mut self , delay : Duration ) {
80+ if self . _reset ( delay) . is_err ( ) {
9281 self . state = None
9382 }
9483 }
9584
96- fn _reset ( & mut self , at : Instant ) -> Result < ( ) , ( ) > {
85+ fn _reset ( & mut self , delay : Duration ) -> Result < ( ) , ( ) > {
9786 let state = match self . state {
9887 Some ( ref state) => state,
9988 None => return Err ( ( ) ) ,
@@ -111,7 +100,7 @@ impl Delay {
111100 Err ( s) => bits = s,
112101 }
113102 }
114- * state. at . lock ( ) . unwrap ( ) = Some ( at ) ;
103+ * state. at . lock ( ) . unwrap ( ) = Some ( Instant :: now ( ) + delay ) ;
115104 // If we fail to push our node then we've become an inert timer, so
116105 // we'll want to clear our `state` field accordingly
117106 timeouts. list . push ( state) ?;
@@ -165,6 +154,6 @@ impl Drop for Delay {
165154
166155impl fmt:: Debug for Delay {
167156 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> Result < ( ) , fmt:: Error > {
168- f. debug_struct ( "Delay" ) . field ( "when" , & self . when ) . finish ( )
157+ f. debug_struct ( "Delay" ) . finish ( )
169158 }
170159}
0 commit comments