1 // This file is Copyright its original authors, visible in version control
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
10 //! Some utilities to make working with the standard library's [`Future`]s easier
12 use crate::prelude::*;
13 use core::future::Future;
14 use core::marker::Unpin;
16 use core::task::{Context, Poll};
18 pub(crate) struct MultiFuturePoller<F: Future<Output = ()> + Unpin>(pub Vec<Option<F>>);
20 impl<F: Future<Output = ()> + Unpin> Future for MultiFuturePoller<F> {
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() {
29 match Pin::new(&mut fut).poll(cx) {
30 Poll::Ready(()) => {},
32 have_pending_futures = true;
33 *fut_option = Some(fut);
37 if have_pending_futures {