@@ -857,21 +857,25 @@ impl<Signer: sign::ecdsa::EcdsaChannelSigner> Persist<Signer> for TestPersister
857
857
}
858
858
}
859
859
860
- type SPSCKVChannelState = Arc < Mutex < ( Option < Result < ( ) , io:: Error > > , Option < Waker > ) > > ;
861
- struct SPSCKVChannel ( SPSCKVChannelState ) ;
862
- impl Future for SPSCKVChannel {
860
+ // A simple multi-producer-single-consumer one-shot channel
861
+ type OneShotChannelState = Arc < Mutex < ( Option < Result < ( ) , io:: Error > > , Option < Waker > ) > > ;
862
+ struct OneShotChannel ( OneShotChannelState ) ;
863
+ impl Future for OneShotChannel {
863
864
type Output = Result < ( ) , io:: Error > ;
864
865
fn poll ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Result < ( ) , io:: Error > > {
865
866
let mut state = self . 0 . lock ( ) . unwrap ( ) ;
867
+ // If the future is complete, take() the result and return it,
866
868
state. 0 . take ( ) . map ( |res| Poll :: Ready ( res) ) . unwrap_or_else ( || {
869
+ // otherwise, store the waker so that the future will be poll()ed again when the result
870
+ // is ready.
867
871
state. 1 = Some ( cx. waker ( ) . clone ( ) ) ;
868
872
Poll :: Pending
869
873
} )
870
874
}
871
875
}
872
876
873
877
pub struct TestStore {
874
- pending_async_writes : Mutex < HashMap < String , Vec < ( usize , SPSCKVChannelState , Vec < u8 > ) > > > ,
878
+ pending_async_writes : Mutex < HashMap < String , Vec < ( usize , OneShotChannelState , Vec < u8 > ) > > > ,
875
879
persisted_bytes : Mutex < HashMap < String , HashMap < String , Vec < u8 > > > > ,
876
880
read_only : bool ,
877
881
}
0 commit comments