#join_all in a no_std environment?

3 messages · Page 1 of 1 (latest)

pastel plover
#

I'm working on a project that uses no_std, but I need to figure out how to do a await on a vector of futures.

I wanted to use future::join_all but it doesn't work because of no_std.

impl Joiner {
    pub fn join_all(mut futures_pin: Pin<Box<VecDeque<Pin<Box<(dyn Future<Output = ()> + 'static)>>>>>) {
        let waker = dummy_waker();
        let mut context = Context::from_waker(&waker);
        let mut futures = futures_pin.as_mut();
        while futures.len() > 0 {
            let mut future = futures.pop_front().unwrap();
            match future.as_mut().poll(&mut context) {
                Poll::Ready(_) => {},
                Poll::Pending => futures.push_back(future),
            }
        }
    }
}

and

let mut futures = Box::pin(VecDeque::new());
            let mut active_ports = Vec::new();
            for i in 0u32..17 {futures.push_back(Box::pin(self.set_port_idle(i)));
            }

            Joiner::join_all(futures);

but

error[E0308]: mismatched types
   --> kernel/src/devices/block/mod.rs:123:30
    |
119 |                     futures.push_back(Box::new(self.set_port_idle(i as usize)));
    |                     -------           ---------------------------------------- this argument has type `Box<impl Future<Output = ()>>`...
    |                     |
    |                     ... which causes `futures` to have type `Box<VecDeque<Box<impl Future<Output = ()>>>>`
...
123 |             Joiner::join_all(futures);
    |             ---------------- ^^^^^^^ expected `dyn Future`, found future
    |             |
    |             arguments to this function are incorrect
    |
    = note: expected struct `Box<VecDeque<Box<(dyn Future<Output = ()> + 'static)>>>`
               found struct `Box<VecDeque<Box<impl Future<Output = ()>>>>`
    = help: you can box the `impl Future<Output = ()>` to coerce it to `Box<(dyn Future<Output = ()> + 'static)>`, but you'll have to change the expected type as well
#

I don't understand why it can't coerce it?

The error seems like it should be able to.

I'm also worried I'm just entirely on the wrong path.

solemn torrent
#

This isn't really join_all, this is an executor, since it takes in futures and runs them in sync context. join_all would return a future. But the one in futures appears to not require std.