[][src]Trait async_speed_limit::clock::Clock

pub trait Clock: Clone + Default {
    type Instant: Copy + Sub<Output = Duration>;
    type Delay: Future<Output = ()> + Unpin;
    fn now(&self) -> Self::Instant;
fn sleep(&self, dur: Duration) -> Self::Delay; }

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>

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

Future type returned by sleep().

Loading content...

Required methods

fn now(&self) -> Self::Instant

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

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.

Loading content...

Implementors

impl Clock for ManualClock[src]

type Instant = Nanoseconds

type Delay = ManualDelay

impl Clock for StandardClock[src]

type Instant = Instant

type Delay = Delay

Loading content...