Expand description
A timer toolkit that is generic over the underlying timer implementation.
This crate does not implement any platform-specific timer but uses a generic abstraction over the timer implementation to provide a set of timer related tools:
This crate currently does not provide any feature beyond the ones that is already provided by
tokio, so this crate is completely not needed if you are already using tokio in your
project.
The core of this crate is the Delay trait, and it is implemented for the following types by
enabling the corresponding features:
| Type | Feature | Target Arch |
|---|---|---|
tokio::time::Sleep | "tokio" | non-wasm32 |
smol::Timer | "smol" | non-wasm32 |
futures_timer::Delay | "futures-timer" | non-wasm32 |
[wasm_timer::Delay] | "wasm-timer" | wasm32 |
[fluvio_wasm_timer::Delay] | "fluvio-wasm-timer" | wasm32 |
§WebAssembly support
Support for wasm32-unknown-unknown target depends on the chosen timer implementation.
wasm-timer and fluvio-wasm-timer are the only two wasm timer implementations that are
currently supported.
§Examples
The usage remains mostly similar to those provided in tokio::time with one additional generic
type parameter D which is the type of the underlying timer implementation. Please refer to the
documentation of the corresponding types for more details.
Modules§
- error
- Error types.
Structs§
- Delay
Queue - A queue of delayed elements. This is ported from
tokio_util::time::delay_queue. - Expired
- An entry in
DelayQueuethat has expired and been removed. - Interval
- An
Intervalallows you to wait on a sequence of instants with a certain duration between each instant. - Key
- Token to a value stored in a
DelayQueue. - Sleep
- A future that completes after a specified duration.
- Timeout
- A timeout future.
Enums§
- Missed
Tick Behavior - Ported from [
tokio::time::interval::MissedTickBehavior]
Traits§
- Delay
- A trait that defines a delay, which is the fundamental building block of this crate.
- Instant
- A trait that defines an instant.
Functions§
- interval
- Creates new
Intervalthat yields with interval of period. The first tick completes immediately. The defaultMissedTickBehaviorisMissedTickBehavior::Burst, but this can be configured by callingInterval::set_missed_tick_behavior. - interval_
at - Creates new
Intervalthat yields with interval of period with the first tick completing at start. The defaultMissedTickBehaviorisMissedTickBehavior::Burst, but this can be configured by callingInterval::set_missed_tick_behavior. - sleep
- Creates a new
Sleepthat completes after the specified duration. - sleep_
until - Creates a new
Sleepthat completes at the specified deadline - timeout
- Creates a new
Timeoutwith a specified duration. - timeout_
at - Creates a new
Timeoutwith a specified deadline.