Skip to content

Commit

Permalink
Update Join documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
matheus-consoli committed Apr 20, 2023
1 parent 8aa5ee9 commit 511049e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
49 changes: 45 additions & 4 deletions src/future/join/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,60 @@ pub(crate) mod vec;
/// Wait for all futures to complete.
///
/// Awaits multiple futures simultaneously, returning the output of the futures
/// once all complete.
/// in the same container type they we're created once all complete.
pub trait Join {
/// The resulting output type.
type Output;

/// Which kind of future are we turning this into?
/// The [`Future`] implementation returned by this method.
type Future: Future<Output = Self::Output>;

/// Waits for multiple futures to complete.
///
/// Awaits multiple futures simultaneously, returning the output of the
/// futures once all 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.
/// ```rust
/// # futures::executor::block_on(async {
/// use futures_concurrency::prelude::*;
///
/// // these can be whatever kind of `Future` you have,
/// // as long as it all have the exactly 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]);
/// # })
/// ```
///
/// But in real world, you might want to wait multiple futures of
/// different types - let's say you're awaiting on custom `async {}` blocks,
/// or that your futures have different `Output` types - for that, you can
/// `join` on tuples.
/// ```rust
/// # futures::executor::block_on(async {
/// use futures_concurrency::prelude::*;
///
/// async fn some_async_fn() -> usize { 3 }
///
/// // these can be whatever kind of `Future` you have,
/// // even those that have totally different concrete 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));
/// # })
/// ```
///
/// <br><br>
/// This function returns a new future which polls all futures concurrently.
fn join(self) -> Self::Future;
}
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
//! remove the need to think of "merge" as a verb, and would enable treating
//! sets of futures concurrently.

#![deny(missing_debug_implementations, nonstandard_style)]
#![warn(missing_docs, unreachable_pub)]
#![allow(non_snake_case)]
Expand Down

0 comments on commit 511049e

Please sign in to comment.