async-fuse
Helpers for "fusing" asynchronous computations.
A fused operation has a well-defined behavior once the operation has completed. In this library, it means that a fused operation that has completed will block forever by returning Poll::Pending.
This is similar to the Fuse type provided in futures-rs, but provides more utility allowing it to interact with types which does not implement FusedFuture or FusedStream as is now the case with all core Tokio types since 1.0.
This is especially useful in combination with optional branches using tokio::select, where the future being polled is optionally set. So instead of requiring a branch precondition, the future will simply be marked as pending indefinitely and behave accordingly when polled.
Features
Examples
This is available as the
stack_tickerexample:
use Fuse;
use Duration;
use time;
let mut duration = from_millis;
let sleep = new;
pin!;
let update_duration = new;
pin!;
for _ in 0..10usize
For some types it might be easier to fuse the value on the heap. To make this easier, we provide the [Fuse::pin] constructor which provides a fused value which is pinned on the heap.
As a result, it looks pretty similar to the above example.
This is available as the
heap_tickerexample:
use Fuse;
use Duration;
use time;
let mut duration = from_millis;
let mut sleep = pin;
let mut update_duration = pin;
for _ in 0..10usize
License: MIT/Apache-2.0