futures_concurrency::future

Trait Join

source
pub trait Join {
    type Output;
    type Future: Future<Output = Self::Output>;

    // Required method
    fn join(self) -> Self::Future;
}
Expand description

Wait for all futures to complete.

Awaits multiple futures simultaneously, returning the output of the futures in the same container type they were created once all complete.

Required Associated Types§

source

type Output

The resulting output type.

source

type Future: Future<Output = Self::Output>

The Future implementation returned by this method.

Required Methods§

source

fn join(self) -> Self::Future

Waits for multiple futures to complete.

Awaits multiple futures simultaneously, returning the output of the futures in the same container type they we’re created once all complete.

§Examples

Awaiting multiple futures of the same type can be done using either a vector or an array.

use futures_concurrency::prelude::*;

// all futures passed here are of the same type
let fut1 = core::future::ready(1);
let fut2 = core::future::ready(2);
let fut3 = core::future::ready(3);

let outputs = [fut1, fut2, fut3].join().await;
assert_eq!(outputs, [1, 2, 3]);

In practice however, it’s common to want to await multiple futures of different types. For example if you have two different async {} blocks, you want to .await. To do that, you can call .join on tuples of futures.

use futures_concurrency::prelude::*;

async fn some_async_fn() -> usize { 3 }

// the futures passed here are of different types
let fut1 = core::future::ready(1);
let fut2 = async { 2 };
let fut3 = some_async_fn();
//                       ^ NOTE: no `.await` here!

let outputs = (fut1, fut2, fut3).join().await;
assert_eq!(outputs, (1, 2, 3));



This function returns a new future which polls all futures concurrently.

Implementations on Foreign Types§

source§

impl Join for ()

source§

type Output = ()

source§

type Future = Join0

source§

fn join(self) -> Self::Future

source§

impl<A> Join for (A,)
where A: IntoFuture,

source§

type Output = (<A as IntoFuture>::Output,)

source§

type Future = Join1<<A as IntoFuture>::IntoFuture>

source§

fn join(self) -> Self::Future

source§

impl<A, B> Join for (A, B)
where A: IntoFuture, B: IntoFuture,

source§

type Output = (<A as IntoFuture>::Output, <B as IntoFuture>::Output)

source§

type Future = Join2<<A as IntoFuture>::IntoFuture, <B as IntoFuture>::IntoFuture>

source§

fn join(self) -> Self::Future

source§

impl<A, B, C> Join for (A, B, C)
where A: IntoFuture, B: IntoFuture, C: IntoFuture,

source§

type Output = (<A as IntoFuture>::Output, <B as IntoFuture>::Output, <C as IntoFuture>::Output)

source§

type Future = Join3<<A as IntoFuture>::IntoFuture, <B as IntoFuture>::IntoFuture, <C as IntoFuture>::IntoFuture>

source§

fn join(self) -> Self::Future

source§

impl<A, B, C, D> Join for (A, B, C, D)

source§

type Output = (<A as IntoFuture>::Output, <B as IntoFuture>::Output, <C as IntoFuture>::Output, <D as IntoFuture>::Output)

source§

type Future = Join4<<A as IntoFuture>::IntoFuture, <B as IntoFuture>::IntoFuture, <C as IntoFuture>::IntoFuture, <D as IntoFuture>::IntoFuture>

source§

fn join(self) -> Self::Future

source§

impl<A, B, C, D, E> Join for (A, B, C, D, E)

source§

impl<A, B, C, D, E, F> Join for (A, B, C, D, E, F)

source§

impl<A, B, C, D, E, F, G> Join for (A, B, C, D, E, F, G)

source§

impl<A, B, C, D, E, F, G, H> Join for (A, B, C, D, E, F, G, H)

source§

impl<A, B, C, D, E, F, G, H, I> Join for (A, B, C, D, E, F, G, H, I)

source§

impl<A, B, C, D, E, F, G, H, I, J> Join for (A, B, C, D, E, F, G, H, I, J)

source§

impl<A, B, C, D, E, F, G, H, I, J, K> Join for (A, B, C, D, E, F, G, H, I, J, K)

source§

impl<A, B, C, D, E, F, G, H, I, J, K, L> Join for (A, B, C, D, E, F, G, H, I, J, K, L)

source§

impl<Fut> Join for Vec<Fut>
where Fut: IntoFuture,

source§

type Output = Vec<<Fut as IntoFuture>::Output>

source§

type Future = Join<<Fut as IntoFuture>::IntoFuture>

source§

fn join(self) -> Self::Future

source§

impl<Fut, const N: usize> Join for [Fut; N]
where Fut: IntoFuture,

source§

type Output = [<Fut as IntoFuture>::Output; N]

source§

type Future = Join<<Fut as IntoFuture>::IntoFuture, N>

source§

fn join(self) -> Self::Future

Implementors§