Skip to content

Commit b579a04

Browse files
committed
f better struct name
1 parent 258d92e commit b579a04

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lightning/src/util/test_utils.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

873877
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>)>>>,
875879
persisted_bytes: Mutex<HashMap<String, HashMap<String, Vec<u8>>>>,
876880
read_only: bool,
877881
}
@@ -1013,7 +1017,7 @@ impl KVStore for TestStore {
10131017
let new_id = pending_writes.last().map(|(id, _, _)| id + 1).unwrap_or(0);
10141018
pending_writes.push((new_id, Arc::clone(&future), buf));
10151019

1016-
Box::pin(SPSCKVChannel(future))
1020+
Box::pin(OneShotChannel(future))
10171021
}
10181022
fn remove(
10191023
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool,

0 commit comments

Comments
 (0)