@@ -25,7 +25,6 @@ use crate::{ScheduledTimer, TimerHandle};
25
25
/// at.
26
26
pub struct Delay {
27
27
state : Option < Arc < Node < ScheduledTimer > > > ,
28
- when : Instant ,
29
28
}
30
29
31
30
impl Delay {
@@ -38,12 +37,6 @@ impl Delay {
38
37
Delay :: new_handle ( Instant :: now ( ) + dur, Default :: default ( ) )
39
38
}
40
39
41
- /// Return the `Instant` when this delay will fire.
42
- #[ inline]
43
- pub fn when ( & self ) -> Instant {
44
- self . when
45
- }
46
-
47
40
/// Creates a new future which will fire at the time specified by `at`.
48
41
///
49
42
/// The returned instance of `Delay` will be bound to the timer specified by
@@ -54,7 +47,6 @@ impl Delay {
54
47
None => {
55
48
return Delay {
56
49
state : None ,
57
- when : at,
58
50
}
59
51
}
60
52
} ;
@@ -72,28 +64,25 @@ impl Delay {
72
64
if inner. list . push ( & state) . is_err ( ) {
73
65
return Delay {
74
66
state : None ,
75
- when : at,
76
67
} ;
77
68
}
78
69
79
70
inner. waker . wake ( ) ;
80
71
Delay {
81
72
state : Some ( state) ,
82
- when : at,
83
73
}
84
74
}
85
75
86
76
/// Resets this timeout to an new timeout which will fire at the time
87
77
/// specified by `at`.
88
78
#[ 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 ( ) {
92
81
self . state = None
93
82
}
94
83
}
95
84
96
- fn _reset ( & mut self , at : Instant ) -> Result < ( ) , ( ) > {
85
+ fn _reset ( & mut self , delay : Duration ) -> Result < ( ) , ( ) > {
97
86
let state = match self . state {
98
87
Some ( ref state) => state,
99
88
None => return Err ( ( ) ) ,
@@ -111,7 +100,7 @@ impl Delay {
111
100
Err ( s) => bits = s,
112
101
}
113
102
}
114
- * state. at . lock ( ) . unwrap ( ) = Some ( at ) ;
103
+ * state. at . lock ( ) . unwrap ( ) = Some ( Instant :: now ( ) + delay ) ;
115
104
// If we fail to push our node then we've become an inert timer, so
116
105
// we'll want to clear our `state` field accordingly
117
106
timeouts. list . push ( state) ?;
@@ -165,6 +154,6 @@ impl Drop for Delay {
165
154
166
155
impl fmt:: Debug for Delay {
167
156
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 ( )
169
158
}
170
159
}
0 commit comments