Skip to content

Commit

Permalink
monotonic clock: introduce duration type, split subscribe
Browse files Browse the repository at this point in the history
We are introducing a `duration` type because it has a distinct meaning
from `instant`: an `instant` can only be compared to other `instant`s
from the exact same `monotonic-clock`, whereas a `duration` represents
a duration of time which can be compared to any other duration of time.

The `duration` type is motivated, in part, by a desire to reuse it to
specify durations such as timeouts in other WASI proposals.

Instead of taking a boolean specifying whether the u64 is an absolute or
relative time, `subscribe-instant` takes an `instant` type and
`subscribe-duration` takes a `duration` type.
  • Loading branch information
Pat Hickey committed Oct 25, 2023
1 parent 1ea8a6d commit 3b25d8e
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions wit/monotonic-clock.wit
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,34 @@
interface monotonic-clock {
use wasi:io/poll.{pollable};

/// A timestamp in nanoseconds.
/// An instant in time, in nanoseconds. An instant is relative to an
/// unspecified initial value, and can only be compared to instances from
/// the same monotonic-clock.
type instant = u64;

/// A duration of time, in nanoseconds.
type duration = u64;

/// Read the current value of the clock.
///
/// The clock is monotonic, therefore calling this function repeatedly will
/// produce a sequence of non-decreasing values.
now: func() -> instant;

/// Query the resolution of the clock.
resolution: func() -> instant;
/// Query the resolution of the clock. Returns the duration of time
/// corresponding to a clock tick.
resolution: func() -> duration;

/// Create a `pollable` which will resolve once the specified time has been
/// reached.
subscribe: func(
/// Create a `pollable` which will resolve once the specified instant
/// occured.
subscribe-instant: func(
when: instant,
absolute: bool
) -> pollable;

/// Create a `pollable` which will resolve once the given duration has
/// elapsed, starting at the time at which this function was called.
/// occured.
subscribe-duration: func(
when: duration,
) -> pollable;
}

0 comments on commit 3b25d8e

Please sign in to comment.