@@ -857,21 +857,25 @@ impl<Signer: sign::ecdsa::EcdsaChannelSigner> Persist<Signer> for TestPersister
857857 }
858858}
859859
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 {
863864 type Output = Result < ( ) , io:: Error > ;
864865 fn poll ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Result < ( ) , io:: Error > > {
865866 let mut state = self . 0 . lock ( ) . unwrap ( ) ;
867+ // If the future is complete, take() the result and return it,
866868 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.
867871 state. 1 = Some ( cx. waker ( ) . clone ( ) ) ;
868872 Poll :: Pending
869873 } )
870874 }
871875}
872876
873877pub 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 > ) > > > ,
875879 persisted_bytes : Mutex < HashMap < String , HashMap < String , Vec < u8 > > > > ,
876880 read_only : bool ,
877881}
0 commit comments