1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
//! [](https://docs.rs/async-fuse) //! [](https://crates.io/crates/async-fuse) //! [](https://github.com/udoprog/async-fuse/actions) //! //! 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: //! > ```sh //! > cargo run --example ticker //! > ``` //! //! ```rust //! use std::time::Duration; //! use tokio::time; //! //! # #[tokio::main] //! # async fn main() { //! 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))); //! } //! } //! } //! # } //! ``` //! //! [tokio::select]: https://docs.rs/tokio/1/tokio/macro.select.html //! [Fuse]: https://docs.rs/futures/0/futures/future/struct.Fuse.html //! [Stream]: https://docs.rs/futures/0/futures/stream/trait.Stream.html //! [Interval]: https://docs.rs/tokio/1/tokio/time/struct.Interval.html #![deny(missing_docs)] mod poll_fn; pub use self::poll_fn::{poll_fn, PollFn}; mod once; pub use self::once::{once, Once};