Skip to content

Commit c380b22

Browse files
committed
f Make poller error type generic
1 parent 3c9d331 commit c380b22

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

lightning/src/onion_message/messenger.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,7 @@ where
13561356
futures.push(handler(ev));
13571357
}
13581358
// Let the `OnionMessageIntercepted` events finish before moving on to peer_connecteds
1359-
crate::util::async_poll::MultiEventFuturePoller::new(futures).await;
1359+
crate::util::async_poll::MultiResultFuturePoller::new(futures).await;
13601360

13611361
if peer_connecteds.len() <= 1 {
13621362
for event in peer_connecteds { handler(event).await; }
@@ -1365,7 +1365,7 @@ where
13651365
for event in peer_connecteds {
13661366
futures.push(handler(event));
13671367
}
1368-
crate::util::async_poll::MultiEventFuturePoller::new(futures).await;
1368+
crate::util::async_poll::MultiResultFuturePoller::new(futures).await;
13691369
}
13701370
}
13711371
}

lightning/src/util/async_poll.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,45 +9,49 @@
99

1010
//! Some utilities to make working with the standard library's [`Future`]s easier
1111
12-
use crate::events::ReplayEvent;
1312
use crate::prelude::*;
1413
use core::future::Future;
1514
use core::marker::Unpin;
1615
use core::pin::Pin;
1716
use core::task::{Context, Poll};
1817

19-
enum EventFuture<F: Future<Output = Result<(), ReplayEvent>>> {
18+
enum ResultFuture<F: Future<Output = Result<(), E>>, E: Copy + Unpin> {
2019
Pending(F),
21-
Ready(Result<(), ReplayEvent>),
20+
Ready(Result<(), E>),
2221
}
2322

24-
pub(crate) struct MultiEventFuturePoller<F: Future<Output = Result<(), ReplayEvent>> + Unpin> {
25-
futures_state: Vec<EventFuture<F>>,
23+
pub(crate) struct MultiResultFuturePoller<
24+
F: Future<Output = Result<(), E>> + Unpin,
25+
E: Copy + Unpin,
26+
> {
27+
futures_state: Vec<ResultFuture<F, E>>,
2628
}
2729

28-
impl<F: Future<Output = Result<(), ReplayEvent>> + Unpin> MultiEventFuturePoller<F> {
30+
impl<F: Future<Output = Result<(), E>> + Unpin, E: Copy + Unpin> MultiResultFuturePoller<F, E> {
2931
pub fn new(futures: Vec<F>) -> Self {
30-
let futures_state = futures.into_iter().map(|f| EventFuture::Pending(f)).collect();
32+
let futures_state = futures.into_iter().map(|f| ResultFuture::Pending(f)).collect();
3133
Self { futures_state }
3234
}
3335
}
3436

35-
impl<F: Future<Output = Result<(), ReplayEvent>> + Unpin> Future for MultiEventFuturePoller<F> {
36-
type Output = Vec<Result<(), ReplayEvent>>;
37-
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Vec<Result<(), ReplayEvent>>> {
37+
impl<F: Future<Output = Result<(), E>> + Unpin, E: Copy + Unpin> Future
38+
for MultiResultFuturePoller<F, E>
39+
{
40+
type Output = Vec<Result<(), E>>;
41+
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Vec<Result<(), E>>> {
3842
let mut have_pending_futures = false;
3943
let futures_state = &mut self.get_mut().futures_state;
4044
for state in futures_state.iter_mut() {
4145
match state {
42-
EventFuture::Pending(ref mut fut) => match Pin::new(fut).poll(cx) {
46+
ResultFuture::Pending(ref mut fut) => match Pin::new(fut).poll(cx) {
4347
Poll::Ready(res) => {
44-
*state = EventFuture::Ready(res);
48+
*state = ResultFuture::Ready(res);
4549
},
4650
Poll::Pending => {
4751
have_pending_futures = true;
4852
},
4953
},
50-
EventFuture::Ready(_) => continue,
54+
ResultFuture::Ready(_) => continue,
5155
}
5256
}
5357

@@ -57,8 +61,8 @@ impl<F: Future<Output = Result<(), ReplayEvent>> + Unpin> Future for MultiEventF
5761
let results = futures_state
5862
.iter()
5963
.filter_map(|e| match e {
60-
EventFuture::Ready(res) => Some(res),
61-
EventFuture::Pending(_) => {
64+
ResultFuture::Ready(res) => Some(res),
65+
ResultFuture::Pending(_) => {
6266
debug_assert!(
6367
false,
6468
"All futures are expected to be ready if none are pending"

0 commit comments

Comments
 (0)