#future #async-await #complete #await #async #completablefuture

manual_future

A future that must be manually completed, similar to Java's CompletableFuture

2 releases

0.1.1 Nov 27, 2019
0.1.0 Nov 23, 2019

#1063 in Asynchronous

Download history 32386/week @ 2024-03-14 27788/week @ 2024-03-21 27762/week @ 2024-03-28 18406/week @ 2024-04-04 27120/week @ 2024-04-11 19554/week @ 2024-04-18 25097/week @ 2024-04-25 14968/week @ 2024-05-02 18591/week @ 2024-05-09 16369/week @ 2024-05-16 32532/week @ 2024-05-23 36471/week @ 2024-05-30 45331/week @ 2024-06-06 27937/week @ 2024-06-13 35980/week @ 2024-06-20 18420/week @ 2024-06-27

132,590 downloads per month
Used in 26 crates (5 directly)

MIT license

8KB
106 lines

manual_future

Explicitly completed Future type for Rust, similar to Java's CompletableFuture

Example

// create a new, incomplete ManualFuture
let (future, completer) = ManualFuture::new();

// complete the future with a value
completer.complete(5).await;

// retrieve the value from the future
assert_eq!(future.await, 5);

// you can also create ManualFuture instances that are already completed
assert_eq!(ManualFuture::new_completed(10).await, 10);

lib.rs:

A Future value that resolves once it's explicitly completed, potentially from a different thread or task, similar to Java's CompletableFuture.

Currently, this is implemented using the BiLock from the futures crate.

Examples

Create an incomplete ManualFuture and explicitly complete it with the completer:

let (future, completer) = ManualFuture::<i32>::new();
block_on(async { completer.complete(5).await });
assert_eq!(block_on(future), 5);

Create an initially complete ManualFuture that can be immediately resolved:

assert_eq!(block_on(ManualFuture::new_completed(10)), 10);

Dependencies

~1MB
~16K SLoC