Trait diem_time_service::TimeServiceTrait[][src]

pub trait TimeServiceTrait: Send + Sync + Clone + Debug {
    fn now(&self) -> Instant;
fn now_unix_time(&self) -> Duration;
fn sleep(&self, duration: Duration) -> Sleep
Notable traits for Sleep
impl Future for Sleep type Output = ();
;
fn sleep_blocking(&self, duration: Duration); fn now_secs(&self) -> u64 { ... }
fn sleep_until(&self, deadline: Instant) -> Sleep
Notable traits for Sleep
impl Future for Sleep type Output = ();
{ ... }
fn interval(&self, period: Duration) -> Interval { ... }
fn interval_at(&self, start: Instant, period: Duration) -> Interval { ... }
fn timeout<F: Future>(&self, duration: Duration, future: F) -> Timeout<F>
Notable traits for Timeout<F>
impl<F: Future> Future for Timeout<F> type Output = Result<F::Output, Elapsed>;
{ ... }
fn timeout_at<F: Future>(&self, deadline: Instant, future: F) -> Timeout<F>
Notable traits for Timeout<F>
impl<F: Future> Future for Timeout<F> type Output = Result<F::Output, Elapsed>;
{ ... } }

Required methods

Query a monotonically nondecreasing clock. Returns an opaque type that can only be compared to other Instants, i.e., this is a monotonic relative time whereas now_unix_time is a non-monotonic absolute time.

On Linux, this is equivalent to clock_gettime(CLOCK_MONOTONIC, _)

See Instant for more details.

Query the current unix timestamp as a Duration.

When used on a TimeService::real(), this is equivalent to SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).

Note: the Duration returned from this function is NOT guaranteed to be monotonic. Use now if you need monotonicity.

From the SystemTime docs:

Distinct from the Instant type, this time measurement is not monotonic. This means that you can save a file to the file system, then save another file to the file system, and the second file has a SystemTime measurement earlier than the first. In other words, an operation that happens after another operation in real time may have an earlier SystemTime!

For example, the system administrator could clock_settime into the past, breaking clock time monotonicity.

On Linux, this is equivalent to clock_gettime(CLOCK_REALTIME, _).

Return a Future that waits until duration has passed.

No work is performed while awaiting on the sleep future to complete. Sleep operates at millisecond granularity and should not be used for tasks that require high-resolution timers.

Cancelation

Canceling a sleep instance is done by dropping the returned future. No additional cleanup work is required.

Blocks the current thread until duration time has passed.

Provided methods

Query the current unix timestamp in seconds.

Equivalent to self.now_unix_time().as_secs(). See now_unix_time.

Return a Future that waits until the deadline.

If the deadline is in the past, the Sleep will trigger as soons as it’s polled.

See sleep for more details.

Creates a new Interval that yields with interval of period. The first tick completes immediately. An interval will tick indefinitely.

Cancelation

At any time, the Interval value can be dropped. This cancels the interval.

Panics

This function panics if period is zero.

Creates a new Interval that yields with interval of period. The first tick completes after the start deadline. An interval will tick indefinitely.

See interval for more details.

Require a Future to complete before the specified duration has elapsed.

If the future completes before the duration has elapsed, then the completed value is returned. Otherwise, Err(Elapsed) is returned and the future is canceled.

Cancelation

Cancelling a timeout is done by dropping the future. No additional cleanup or other work is required.

The original future may be obtained by calling Timeout::into_inner. This consumes the Timeout.

Require a Future to complete before the deadline.

If the future completes before the duration has elapsed, then the completed value is returned. Otherwise, Err(Elapsed) is returned and the future is canceled.

See timeout for more details.

Implementors