#future #concurrency #async #stream #structured #operations #multiple

no-std futures-concurrency

Structured concurrency operations for async Rust

26 stable releases (6 major)

7.6.0 Apr 12, 2024
7.5.0 Mar 11, 2024
7.4.3 Sep 22, 2023
7.3.0 Jun 23, 2023
1.1.0 Oct 19, 2021

#13 in Asynchronous

Download history 4668/week @ 2023-12-23 6738/week @ 2023-12-30 11900/week @ 2024-01-06 13306/week @ 2024-01-13 15038/week @ 2024-01-20 14198/week @ 2024-01-27 9749/week @ 2024-02-03 14648/week @ 2024-02-10 15050/week @ 2024-02-17 13283/week @ 2024-02-24 14362/week @ 2024-03-02 16460/week @ 2024-03-09 16275/week @ 2024-03-16 14509/week @ 2024-03-23 13637/week @ 2024-03-30 13432/week @ 2024-04-06

60,775 downloads per month
Used in 65 crates (18 directly)

MIT/Apache

295KB
6.5K SLoC

futures-concurrency

Structured concurrency operations for async Rust

Performant, portable, structured concurrency operations for async Rust. It works with any runtime, does not erase lifetimes, always handles cancellation, and always returns output to the caller.

futures-concurrency provides concurrency operations for both groups of futures and streams. Both for bounded and unbounded sets of futures and streams. In both cases performance should be on par with, if not exceed conventional executor implementations.

Examples

Await multiple futures of different types

use futures_concurrency::prelude::*;
use std::future;

let a = future::ready(1u8);
let b = future::ready("hello");
let c = future::ready(3u16);
assert_eq!((a, b, c).join().await, (1, "hello", 3));

Concurrently process items in a stream

use futures_concurrency::prelude::*;

let v: Vec<_> = vec!["chashu", "nori"]
    .into_co_stream()
    .map(|msg| async move { format!("hello {msg}") })
    .collect()
    .await;

assert_eq!(v, &["hello chashu", "hello nori"]);

Access stack data outside the futures' scope

Adapted from std::thread::scope.

use futures_concurrency::prelude::*;

let mut container = vec![1, 2, 3];
let mut num = 0;

let a = async {
    println!("hello from the first future");
    dbg!(&container);
};

let b = async {
    println!("hello from the second future");
    num += container[0] + container[2];
};

println!("hello from the main future");
let _ = (a, b).join().await;
container.push(4);
assert_eq!(num, container.len());

Installation

$ cargo add futures-concurrency

Contributing

Want to join us? Check out our "Contributing" guide and take a look at some of these issues:

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~1.5–2MB
~47K SLoC