5
5
6
6
use std:: fmt;
7
7
use std:: future:: Future ;
8
+ use std:: io;
8
9
use std:: pin:: Pin ;
9
10
use std:: sync:: atomic:: AtomicUsize ;
10
11
use std:: sync:: atomic:: Ordering :: SeqCst ;
@@ -125,16 +126,19 @@ impl Delay {
125
126
}
126
127
127
128
impl Future for Delay {
128
- type Output = ( ) ;
129
+ type Output = io :: Result < ( ) > ;
129
130
130
131
fn poll ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
131
132
let state = match self . state {
132
133
Some ( ref state) => state,
133
- None => panic ! ( "timer has gone away" ) ,
134
+ None => {
135
+ let err = Err ( io:: Error :: new ( io:: ErrorKind :: Other , "timer has gone away" ) ) ;
136
+ return Poll :: Ready ( err) ;
137
+ }
134
138
} ;
135
139
136
140
if state. state . load ( SeqCst ) & 1 != 0 {
137
- return Poll :: Ready ( ( ) ) ;
141
+ return Poll :: Ready ( Ok ( ( ) ) ) ;
138
142
}
139
143
140
144
state. waker . register ( & cx. waker ( ) ) ;
@@ -143,8 +147,11 @@ impl Future for Delay {
143
147
// state. If we've fired the first bit is set, and if we've been
144
148
// invalidated the second bit is set.
145
149
match state. state . load ( SeqCst ) {
146
- n if n & 0b01 != 0 => Poll :: Ready ( ( ) ) ,
147
- n if n & 0b10 != 0 => panic ! ( "timer has gone away" ) ,
150
+ n if n & 0b01 != 0 => Poll :: Ready ( Ok ( ( ) ) ) ,
151
+ n if n & 0b10 != 0 => Poll :: Ready ( Err ( io:: Error :: new (
152
+ io:: ErrorKind :: Other ,
153
+ "timer has gone away" ,
154
+ ) ) ) ,
148
155
_ => Poll :: Pending ,
149
156
}
150
157
}
0 commit comments