Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yoshuawuyts/futures-concurrency
Structured concurrency operations for async Rust
https://github.com/yoshuawuyts/futures-concurrency
async futures rust structured-concurrency
Last synced: about 5 hours ago
JSON representation
Structured concurrency operations for async Rust
- Host: GitHub
- URL: https://github.com/yoshuawuyts/futures-concurrency
- Owner: yoshuawuyts
- License: apache-2.0
- Created: 2021-08-29T17:50:52.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-24T15:46:07.000Z (20 days ago)
- Last Synced: 2024-11-06T08:43:12.299Z (7 days ago)
- Topics: async, futures, rust, structured-concurrency
- Language: Rust
- Homepage: https://docs.rs/futures-concurrency
- Size: 589 KB
- Stars: 406
- Watchers: 10
- Forks: 32
- Open Issues: 32
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE-APACHE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
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**
```rust
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**
```rust
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`](https://doc.rust-lang.org/std/thread/fn.scope.html)._
```rust
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
```sh
$ cargo add futures-concurrency
```## Contributing
Want to join us? Check out our ["Contributing" guide][contributing] and take a
look at some of these issues:- [Issues labeled "good first issue"][good-first-issue]
- [Issues labeled "help wanted"][help-wanted][contributing]: https://github.com/yoshuawuyts/futures-concurrency/blob/master.github/CONTRIBUTING.md
[good-first-issue]: https://github.com/yoshuawuyts/futures-concurrency/labels/good%20first%20issue
[help-wanted]: https://github.com/yoshuawuyts/futures-concurrency/labels/help%20wanted## 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.