Skip to content

Commit c47ca84

Browse files
committed
f Wake waker on Ready
1 parent e0e7a60 commit c47ca84

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

lightning/src/util/test_utils.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,32 +1006,32 @@ impl KVStoreSync for TestStore {
10061006

10071007
// A `Future` that returns the result only on the second poll.
10081008
pub(crate) struct TestStoreFuture<R> {
1009-
inner: Mutex<(bool, Option<io::Result<R>>)>,
1009+
inner: Mutex<(Option<core::task::Waker>, Option<io::Result<R>>)>,
10101010
}
10111011

10121012
impl<R> TestStoreFuture<R> {
10131013
fn new(res: io::Result<R>) -> Self {
1014-
let inner = Mutex::new((true, Some(res)));
1014+
let inner = Mutex::new((None, Some(res)));
10151015
Self { inner }
10161016
}
10171017
}
10181018

10191019
impl<R> Future for TestStoreFuture<R> {
10201020
type Output = Result<R, io::Error>;
10211021
fn poll(
1022-
self: Pin<&mut Self>, _cx: &mut core::task::Context<'_>,
1022+
self: Pin<&mut Self>, cx: &mut core::task::Context<'_>,
10231023
) -> core::task::Poll<Self::Output> {
10241024
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());
10281028
core::task::Poll::Pending
10291029
} 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)
10351035
}
10361036
}
10371037
}

0 commit comments

Comments
 (0)