@@ -45,7 +45,7 @@ impl Notifier {
45
45
pub ( crate ) fn notify ( & self ) {
46
46
let mut lock = self . notify_pending . lock ( ) . unwrap ( ) ;
47
47
if let Some ( future_state) = & lock. 1 {
48
- if future_state . lock ( ) . unwrap ( ) . complete ( ) {
48
+ if complete_future ( future_state ) {
49
49
lock. 1 = None ;
50
50
return ;
51
51
}
@@ -116,15 +116,15 @@ pub(crate) struct FutureState {
116
116
callbacks_made : bool ,
117
117
}
118
118
119
- impl FutureState {
120
- fn complete ( & mut self ) -> bool {
121
- for ( counts_as_call, callback) in self . callbacks . drain ( ..) {
122
- callback. call ( ) ;
123
- self . callbacks_made |= counts_as_call;
124
- }
125
- self . complete = true ;
126
- self . callbacks_made
119
+ fn complete_future ( this : & Arc < Mutex < FutureState > > ) -> bool {
120
+ let mut state_lock = this. lock ( ) . unwrap ( ) ;
121
+ let state = & mut * state_lock;
122
+ for ( counts_as_call, callback) in state. callbacks . drain ( ..) {
123
+ callback. call ( ) ;
124
+ state. callbacks_made |= counts_as_call;
127
125
}
126
+ state. complete = true ;
127
+ state. callbacks_made
128
128
}
129
129
130
130
/// A simple future which can complete once, and calls some callback(s) when it does so.
@@ -421,9 +421,9 @@ mod tests {
421
421
future. register_callback ( Box :: new ( move || assert ! ( !callback_ref. fetch_or( true , Ordering :: SeqCst ) ) ) ) ;
422
422
423
423
assert ! ( !callback. load( Ordering :: SeqCst ) ) ;
424
- future. state . lock ( ) . unwrap ( ) . complete ( ) ;
424
+ complete_future ( & future. state ) ;
425
425
assert ! ( callback. load( Ordering :: SeqCst ) ) ;
426
- future. state . lock ( ) . unwrap ( ) . complete ( ) ;
426
+ complete_future ( & future. state ) ;
427
427
}
428
428
429
429
#[ test]
@@ -435,7 +435,7 @@ mod tests {
435
435
callbacks_made : false ,
436
436
} ) )
437
437
} ;
438
- future. state . lock ( ) . unwrap ( ) . complete ( ) ;
438
+ complete_future ( & future. state ) ;
439
439
440
440
let callback = Arc :: new ( AtomicBool :: new ( false ) ) ;
441
441
let callback_ref = Arc :: clone ( & callback) ;
@@ -483,7 +483,7 @@ mod tests {
483
483
assert_eq ! ( Pin :: new( & mut second_future) . poll( & mut Context :: from_waker( & second_waker) ) , Poll :: Pending ) ;
484
484
assert ! ( !second_woken. load( Ordering :: SeqCst ) ) ;
485
485
486
- future. state . lock ( ) . unwrap ( ) . complete ( ) ;
486
+ complete_future ( & future. state ) ;
487
487
assert ! ( woken. load( Ordering :: SeqCst ) ) ;
488
488
assert ! ( second_woken. load( Ordering :: SeqCst ) ) ;
489
489
assert_eq ! ( Pin :: new( & mut future) . poll( & mut Context :: from_waker( & waker) ) , Poll :: Ready ( ( ) ) ) ;
0 commit comments