summaryrefslogtreecommitdiffstats
path: root/third_party/rust/tokio-0.1.22/src/timer.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /third_party/rust/tokio-0.1.22/src/timer.rs
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/tokio-0.1.22/src/timer.rs')
-rw-r--r--third_party/rust/tokio-0.1.22/src/timer.rs94
1 files changed, 94 insertions, 0 deletions
diff --git a/third_party/rust/tokio-0.1.22/src/timer.rs b/third_party/rust/tokio-0.1.22/src/timer.rs
new file mode 100644
index 0000000000..888e7a9db1
--- /dev/null
+++ b/third_party/rust/tokio-0.1.22/src/timer.rs
@@ -0,0 +1,94 @@
+//! Utilities for tracking time.
+//!
+//! This module provides a number of types for executing code after a set period
+//! of time.
+//!
+//! * [`Delay`][Delay] is a future that does no work and completes at a specific `Instant`
+//! in time.
+//!
+//! * [`Interval`][Interval] is a stream yielding a value at a fixed period. It
+//! is initialized with a `Duration` and repeatedly yields each time the
+//! duration elapses.
+//!
+//! * [`Timeout`][Timeout]: Wraps a future or stream, setting an upper bound to the
+//! amount of time it is allowed to execute. If the future or stream does not
+//! complete in time, then it is canceled and an error is returned.
+//!
+//! * [`DelayQueue`]: A queue where items are returned once the requested delay
+//! has expired.
+//!
+//! These types are sufficient for handling a large number of scenarios
+//! involving time.
+//!
+//! These types must be used from within the context of the
+//! [`Runtime`][runtime] or a timer context must be setup explicitly. See the
+//! [`tokio-timer`][tokio-timer] crate for more details on how to setup a timer
+//! context.
+//!
+//! # Examples
+//!
+//! Wait 100ms and print "Hello World!"
+//!
+//! ```
+//! use tokio::prelude::*;
+//! use tokio::timer::Delay;
+//!
+//! use std::time::{Duration, Instant};
+//!
+//! let when = Instant::now() + Duration::from_millis(100);
+//!
+//! tokio::run({
+//! Delay::new(when)
+//! .map_err(|e| panic!("timer failed; err={:?}", e))
+//! .and_then(|_| {
+//! println!("Hello world!");
+//! Ok(())
+//! })
+//! })
+//! ```
+//!
+//! Require that an operation takes no more than 300ms. Note that this uses the
+//! [`timeout`][ext] function on the [`FutureExt`][ext] trait. This trait is
+//! included in the prelude.
+//!
+//! ```
+//! # extern crate futures;
+//! # extern crate tokio;
+//! use tokio::prelude::*;
+//!
+//! use std::time::{Duration, Instant};
+//!
+//! fn long_op() -> Box<Future<Item = (), Error = ()> + Send> {
+//! // ...
+//! # Box::new(futures::future::ok(()))
+//! }
+//!
+//! # fn main() {
+//! tokio::run({
+//! long_op()
+//! .timeout(Duration::from_millis(300))
+//! .map_err(|e| {
+//! println!("operation timed out");
+//! })
+//! })
+//! # }
+//! ```
+//!
+//! [runtime]: ../runtime/struct.Runtime.html
+//! [tokio-timer]: https://docs.rs/tokio-timer
+//! [ext]: ../util/trait.FutureExt.html#method.timeout
+//! [Timeout]: struct.Timeout.html
+//! [Delay]: struct.Delay.html
+//! [Interval]: struct.Interval.html
+//! [`DelayQueue`]: struct.DelayQueue.html
+
+pub use tokio_timer::{delay_queue, timeout, Delay, DelayQueue, Error, Interval, Timeout};
+
+#[deprecated(since = "0.1.8", note = "use Timeout instead")]
+#[allow(deprecated)]
+#[doc(hidden)]
+pub type Deadline<T> = ::tokio_timer::Deadline<T>;
+#[deprecated(since = "0.1.8", note = "use Timeout instead")]
+#[allow(deprecated)]
+#[doc(hidden)]
+pub type DeadlineError<T> = ::tokio_timer::DeadlineError<T>;