@@ -1006,32 +1006,32 @@ impl KVStoreSync for TestStore {
1006
1006
1007
1007
// A `Future` that returns the result only on the second poll.
1008
1008
pub ( crate ) struct TestStoreFuture < R > {
1009
- inner : Mutex < ( bool , Option < io:: Result < R > > ) > ,
1009
+ inner : Mutex < ( Option < core :: task :: Waker > , Option < io:: Result < R > > ) > ,
1010
1010
}
1011
1011
1012
1012
impl < R > TestStoreFuture < R > {
1013
1013
fn new ( res : io:: Result < R > ) -> Self {
1014
- let inner = Mutex :: new ( ( true , Some ( res) ) ) ;
1014
+ let inner = Mutex :: new ( ( None , Some ( res) ) ) ;
1015
1015
Self { inner }
1016
1016
}
1017
1017
}
1018
1018
1019
1019
impl < R > Future for TestStoreFuture < R > {
1020
1020
type Output = Result < R , io:: Error > ;
1021
1021
fn poll (
1022
- self : Pin < & mut Self > , _cx : & mut core:: task:: Context < ' _ > ,
1022
+ self : Pin < & mut Self > , cx : & mut core:: task:: Context < ' _ > ,
1023
1023
) -> core:: task:: Poll < Self :: Output > {
1024
1024
let mut inner_lock = self . inner . lock ( ) . unwrap ( ) ;
1025
- let first_poll = & mut inner_lock. 0 ;
1026
- if * first_poll {
1027
- * first_poll = false ;
1025
+ let first_poll = inner_lock. 0 . is_none ( ) ;
1026
+ if first_poll {
1027
+ ( * inner_lock ) . 0 = Some ( cx . waker ( ) . clone ( ) ) ;
1028
1028
core:: task:: Poll :: Pending
1029
1029
} else {
1030
- if let Some ( res ) = inner_lock. 1 . take ( ) {
1031
- core :: task :: Poll :: Ready ( res)
1032
- } else {
1033
- unreachable ! ( "We should never poll more than twice" ) ;
1034
- }
1030
+ let waker = inner_lock. 0 . take ( ) . expect ( "We should never poll more than twice" ) ;
1031
+ let res = inner_lock . 1 . take ( ) . expect ( "We should never poll more than twice" ) ;
1032
+ drop ( inner_lock ) ;
1033
+ waker . wake ( ) ;
1034
+ core :: task :: Poll :: Ready ( res )
1035
1035
}
1036
1036
}
1037
1037
}
0 commit comments