Expose send_payment_for_bolt12_invoice
[rust-lightning] / lightning / src / util / async_poll.rs
1 // This file is Copyright its original authors, visible in version control
2 // history.
3 //
4 // This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
5 // or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
7 // You may not use this file except in accordance with one or both of these
8 // licenses.
9
10 //! Some utilities to make working with the standard library's [`Future`]s easier
11
12 use crate::prelude::*;
13 use core::future::Future;
14 use core::marker::Unpin;
15 use core::pin::Pin;
16 use core::task::{Context, Poll};
17
18 pub(crate) struct MultiFuturePoller<F: Future<Output = ()> + Unpin>(pub Vec<Option<F>>);
19
20 impl<F: Future<Output = ()> + Unpin> Future for MultiFuturePoller<F> {
21         type Output = ();
22         fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
23                 let mut have_pending_futures = false;
24                 for fut_option in self.get_mut().0.iter_mut() {
25                         let mut fut = match fut_option.take() {
26                                 None => continue,
27                                 Some(fut) => fut,
28                         };
29                         match Pin::new(&mut fut).poll(cx) {
30                                 Poll::Ready(()) => {},
31                                 Poll::Pending => {
32                                         have_pending_futures = true;
33                                         *fut_option = Some(fut);
34                                 },
35                         }
36                 }
37                 if have_pending_futures {
38                         Poll::Pending
39                 } else {
40                         Poll::Ready(())
41                 }
42         }
43 }