@@ -190,7 +190,7 @@ pub enum TimeoutAction {
190190#[ derive( Debug ) ]
191191struct TimeoutData {
192192 deadline : Instant ,
193- token : RefCell < Option < Token > > ,
193+ token : Token ,
194194 counter : u32 ,
195195}
196196
@@ -212,7 +212,7 @@ impl TimerWheel {
212212 pub ( crate ) fn insert ( & mut self , deadline : Instant , token : Token ) -> u32 {
213213 self . heap . push ( TimeoutData {
214214 deadline,
215- token : RefCell :: new ( Some ( token ) ) ,
215+ token,
216216 counter : self . counter ,
217217 } ) ;
218218 let ret = self . counter ;
@@ -223,7 +223,7 @@ impl TimerWheel {
223223 pub ( crate ) fn insert_reuse ( & mut self , counter : u32 , deadline : Instant , token : Token ) {
224224 self . heap . push ( TimeoutData {
225225 deadline,
226- token : RefCell :: new ( Some ( token ) ) ,
226+ token,
227227 counter,
228228 } ) ;
229229 }
@@ -243,25 +243,12 @@ impl TimerWheel {
243243 }
244244
245245 pub ( crate ) fn next_expired ( & mut self , now : Instant ) -> Option < ( u32 , Token ) > {
246- loop {
247- // check if there is an expired item
248- if let Some ( data) = self . heap . peek ( ) {
249- if data. deadline > now {
250- return None ;
251- }
252- // there is an expired timeout, continue the
253- // loop body
254- } else {
255- return None ;
256- }
246+ // check if there is an expired item
247+ self . heap . peek ( ) . filter ( |data| now >= data. deadline ) ?;
257248
258- // There is an item in the heap, this unwrap cannot blow
259- let data = self . heap . pop ( ) . unwrap ( ) ;
260- if let Some ( token) = data. token . into_inner ( ) {
261- return Some ( ( data. counter , token) ) ;
262- }
263- // otherwise this timeout was cancelled, continue looping
264- }
249+ // There is an item in the heap, this unwrap cannot blow
250+ let data = self . heap . pop ( ) . unwrap ( ) ;
251+ Some ( ( data. counter , data. token ) )
265252 }
266253
267254 pub ( crate ) fn next_deadline ( & self ) -> Option < std:: time:: Instant > {
0 commit comments