Trait async_speed_limit::clock::Clock [−][src]
A Clock
controls the passing of time.
Limiter
uses sleep()
to impose speed
limit, and it relies on the current and past timestamps to determine how
long to sleep. Both of these time-related features are encapsulated into
this Clock
trait.
Implementing
The StandardClock
should be enough in most situation. However, these are
cases for a custom clock, e.g. use a coarse clock instead of the standard
high-precision clock, or use a specialized future associated with an
executor instead of the generic futures-timer
.
Types implementing Clock
must be cheap to clone (e.g. using Arc
), and
the default value must be ready to use.
Associated Types
type Instant: Copy + Sub<Output = Duration>
[src]
Type to represent a point of time.
Subtracting two instances should return the duration elapsed between them. The subtraction must never block or panic when they are properly ordered.
type Delay: Future<Output = ()> + Unpin
[src]
Future type returned by sleep()
.
Required methods
fn now(&self) -> Self::Instant
[src]
Returns the current time instant. It should be monotonically increasing, but not necessarily high-precision or steady.
This function must never block or panic.
fn sleep(&self, dur: Duration) -> Self::Delay
[src]
Asynchronously sleeps the current task for the given duration.
This method should return a future which fulfilled as ()
after a
duration of dur
. It should not block the current thread.
sleep()
is often called with a duration of 0 s. This should result in
a future being resolved immediately.