futures_time/future/
mod.rs

1//! Asynchronous values.
2//!
3//! # Cancellation
4//!
5//! Futures can be cancelled by dropping them before they finish executing. This
6//! is useful when we're no longer interested in the result of an operation, as
7//! it allows us to stop doing needless work. This also means that a future may cancel at any `.await` point, and so just
8//! like with `?` we have to be careful to roll back local state if our future
9//! halts there.
10//!
11//! In order to perform a cancellation remotely, you can use the [`channel::bounded`]
12//! function to create a sender/receiver pair. When the sender side of
13//! this pair emits a message, all receivers are trigered. Receivers can be passed to
14//! [`Future::timeout`] or [`Stream::timeout`] to perform a cancellation when
15//! the message is received.
16//!
17//! [`channel::bounded`]: crate::channel::bounded
18//! [`Future::timeout`]: crate::future::FutureExt::timeout
19//! [`Stream::timeout`]: crate::stream::StreamExt::timeout
20//!
21//!
22//! ```
23//! use futures_lite::prelude::*;
24//! use futures_time::prelude::*;
25//! use futures_time::channel;
26//! use futures_time::time::Duration;
27//!
28//! async_io::block_on(async {
29//!     let (send, mut recv) = channel::bounded::<()>(1); // create a new send/receive pair
30//!     let mut counter = 0;
31//!     let value = async { "meow" }
32//!         .delay(Duration::from_millis(100))
33//!         .timeout(recv.next()) // time-out if the sender is dropped.
34//!         .await;
35//!
36//!     assert_eq!(value.unwrap(), "meow");
37//! })
38//! ```
39
40mod delay;
41mod future_ext;
42mod into_future;
43mod park;
44mod relative_future;
45mod timeout;
46
47pub use delay::Delay;
48pub use future_ext::FutureExt;
49pub use into_future::IntoFuture;
50pub use park::Park;
51pub use relative_future::Timer;
52pub use timeout::Timeout;