Expand description
Structured parallel execution for async Rust.
Concurrency is a system-structuring mechanism, parallelism is a resource.
This is a replacement for the common Task
idiom. Rather than providing a
separate family of APIs for concurrency and parallelism, this library
provides a ParallelFuture
type. When this type is scheduled concurrently
it will provide parallel execution.
§Examples
use parallel_future::prelude::*;
use futures_concurrency::prelude::*;
async_std::task::block_on(async {
let a = async { 1 }.par(); // ← returns `ParallelFuture`
let b = async { 2 }.par(); // ← returns `ParallelFuture`
let (a, b) = (a, b).join().await; // ← concurrent `.await`
assert_eq!(a + b, 3);
})
§Limitations
Rust does not yet provide a mechanism for async destructors. That means that
on an early return of any kind, Rust can’t guarantee that certain
asynchronous operations run before others. This is a language-level
limitation with no existing workarounds possible. ParallelFuture
is designed to
work with async destructors once they land.
ParallelFuture
starts lazily and does not provide a manual detach
method. However it can be manually polled once and then passed to
mem::forget
, which will keep the future running on another thread. In the
absence of unforgettable types (linear types), Rust cannot prevent
ParallelFuture
s from becoming unmanaged (dangling).
Modules§
- prelude
- The
parallel-future
prelude.
Structs§
- Parallel
Future - A parallelizable future.
Traits§
- Into
Future Ext - Extend the
Future
trait.