Structured concurrency operations for async Rust
See the codePerformant, 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.
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());
$ cargo add futures-concurrency
Want to join us? Check out our "Contributing" guide and take a look at some of these issues:
Overall
Maintained
Code review
crates.io
Latest release
Releases this year
(top 24 of 39)
1,444 followers · starred Oct 2023
1,749 followers · starred Aug 2021
334 followers · starred Mar 2024
161 followers · starred Apr 2024
Structured concurrency operations for async Rust
See the codePerformant, 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.
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());
$ cargo add futures-concurrency
Want to join us? Check out our "Contributing" guide and take a look at some of these issues:
Overall
Maintained
Code review
crates.io
Latest release
Releases this year
(top 24 of 39)
1,444 followers · starred Oct 2023
1,749 followers · starred Aug 2021
334 followers · starred Mar 2024
161 followers · starred Apr 2024