Sha256: 6adacfca4d33a769dbe72fd04c54b49580ecd7a9994a185cfe97dd7a2b55c298

Contents?: true

Size: 1.16 KB

Versions: 27

Compression:

Stored size: 1.16 KB

Contents

use futures::executor::block_on;
use futures::future::{join_all, ready, Future, JoinAll};
use futures::pin_mut;
use std::fmt::Debug;

#[track_caller]
fn assert_done<T>(actual_fut: impl Future<Output = T>, expected: T)
where
    T: PartialEq + Debug,
{
    pin_mut!(actual_fut);
    let output = block_on(actual_fut);
    assert_eq!(output, expected);
}

#[test]
fn collect_collects() {
    assert_done(join_all(vec![ready(1), ready(2)]), vec![1, 2]);
    assert_done(join_all(vec![ready(1)]), vec![1]);
    // REVIEW: should this be implemented?
    // assert_done(join_all(Vec::<i32>::new()), vec![]);

    // TODO: needs more tests
}

#[test]
fn join_all_iter_lifetime() {
    // In futures-rs version 0.1, this function would fail to typecheck due to an overly
    // conservative type parameterization of `JoinAll`.
    fn sizes(bufs: Vec<&[u8]>) -> impl Future<Output = Vec<usize>> {
        let iter = bufs.into_iter().map(|b| ready::<usize>(b.len()));
        join_all(iter)
    }

    assert_done(sizes(vec![&[1, 2, 3], &[], &[0]]), vec![3_usize, 0, 1]);
}

#[test]
fn join_all_from_iter() {
    assert_done(vec![ready(1), ready(2)].into_iter().collect::<JoinAll<_>>(), vec![1, 2])
}

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
wasmtime-30.0.2 ./ext/cargo-vendor/futures-0.3.31/tests/future_join_all.rs
wasmtime-29.0.0 ./ext/cargo-vendor/futures-0.3.31/tests/future_join_all.rs
wasmtime-28.0.0 ./ext/cargo-vendor/futures-0.3.31/tests/future_join_all.rs
wasmtime-27.0.0 ./ext/cargo-vendor/futures-0.3.31/tests/future_join_all.rs
wasmtime-26.0.0 ./ext/cargo-vendor/futures-0.3.31/tests/future_join_all.rs
wasmtime-25.0.2 ./ext/cargo-vendor/futures-0.3.30/tests/future_join_all.rs
wasmtime-25.0.1 ./ext/cargo-vendor/futures-0.3.30/tests/future_join_all.rs
wasmtime-25.0.0 ./ext/cargo-vendor/futures-0.3.30/tests/future_join_all.rs
wasmtime-24.0.0 ./ext/cargo-vendor/futures-0.3.30/tests/future_join_all.rs
wasmtime-23.0.2 ./ext/cargo-vendor/futures-0.3.30/tests/future_join_all.rs
wasmtime-22.0.0 ./ext/cargo-vendor/futures-0.3.30/tests/future_join_all.rs
wasmtime-21.0.1 ./ext/cargo-vendor/futures-0.3.30/tests/future_join_all.rs
wasmtime-20.0.2 ./ext/cargo-vendor/futures-0.3.30/tests/future_join_all.rs
wasmtime-20.0.0 ./ext/cargo-vendor/futures-0.3.30/tests/future_join_all.rs
wasmtime-18.0.3 ./ext/cargo-vendor/futures-0.3.30/tests/future_join_all.rs
wasmtime-17.0.1 ./ext/cargo-vendor/futures-0.3.30/tests/future_join_all.rs
wasmtime-17.0.0 ./ext/cargo-vendor/futures-0.3.30/tests/future_join_all.rs
wasmtime-16.0.0 ./ext/cargo-vendor/futures-0.3.30/tests/future_join_all.rs
wasmtime-15.0.1 ./ext/cargo-vendor/futures-0.3.30/tests/future_join_all.rs
wasmtime-15.0.0 ./ext/cargo-vendor/futures-0.3.30/tests/future_join_all.rs