[][src]Crate async_fuse

Documentation Crates Actions Status

Helpers for fusing asynchronous computations.

This is especially useful in combination with optional branches using tokio::select, where the future being polled isn't necessarily set.

A similar structure is provided by futures-rs called Fuse. This however lacks some of the flexibility needed to interact with tokio's streaming types like Interval since these no longer implement Stream.

Examples

This is available as the ticker example:

cargo run --example ticker
use std::time::Duration;
use tokio::time;

let mut interval = async_fuse::poll_fn(
    time::interval(Duration::from_secs(1)),
    time::Interval::poll_tick,
);

let sleep = async_fuse::once(time::sleep(Duration::from_secs(5)));
tokio::pin!(sleep);

for _ in 0..20usize {
    tokio::select! {
        when = &mut interval => {
            println!("tick: {:?}", when);
        }
        _ = &mut sleep => {
            interval.set(time::interval(Duration::from_millis(200)));
        }
    }
}

Structs

Once

Fusing adapter that is capable of polling an interior value that is being fused using a custom polling function.

PollFn

Fusing adapter that is capable of polling an interior value that is being fused using a custom polling function.

Functions

once

Construct a fusing adapter that is capable of polling an interior future.

poll_fn

Construct a fusing adapter that is capable of polling an interior value that is being polled using a custom function.