| 1 |
package wasi:[email protected]; |
| 2 |
|
| 3 |
/// WASI Monotonic Clock is a clock API intended to let users measure elapsed |
| 4 |
/// time. |
| 5 |
/// |
| 6 |
/// It is intended to be portable at least between Unix-family platforms and |
| 7 |
/// Windows. |
| 8 |
/// |
| 9 |
/// A monotonic clock is a clock which has an unspecified initial value, and |
| 10 |
/// successive reads of the clock will produce non-decreasing values. |
| 11 |
/// |
| 12 |
/// It is intended for measuring elapsed time. |
| 13 |
interface monotonic-clock { |
| 14 |
use wasi:io/[email protected].{pollable}; |
| 15 |
|
| 16 |
/// An instant in time, in nanoseconds. An instant is relative to an |
| 17 |
/// unspecified initial value, and can only be compared to instances from |
| 18 |
/// the same monotonic-clock. |
| 19 |
type instant = u64; |
| 20 |
|
| 21 |
/// A duration of time, in nanoseconds. |
| 22 |
type duration = u64; |
| 23 |
|
| 24 |
/// Read the current value of the clock. |
| 25 |
/// |
| 26 |
/// The clock is monotonic, therefore calling this function repeatedly will |
| 27 |
/// produce a sequence of non-decreasing values. |
| 28 |
now: func() -> instant; |
| 29 |
|
| 30 |
/// Query the resolution of the clock. Returns the duration of time |
| 31 |
/// corresponding to a clock tick. |
| 32 |
resolution: func() -> duration; |
| 33 |
|
| 34 |
/// Create a `pollable` which will resolve once the specified instant |
| 35 |
/// occured. |
| 36 |
subscribe-instant: func(when: instant) -> pollable; |
| 37 |
|
| 38 |
/// Create a `pollable` which will resolve once the given duration has |
| 39 |
/// elapsed, starting at the time at which this function was called. |
| 40 |
/// occured. |
| 41 |
subscribe-duration: func(when: duration) -> pollable; |
| 42 |
} |
| 43 |
|
| 44 |
/// WASI Wall Clock is a clock API intended to let users query the current |
| 45 |
/// time. The name "wall" makes an analogy to a "clock on the wall", which |
| 46 |
/// is not necessarily monotonic as it may be reset. |
| 47 |
/// |
| 48 |
/// It is intended to be portable at least between Unix-family platforms and |
| 49 |
/// Windows. |
| 50 |
/// |
| 51 |
/// A wall clock is a clock which measures the date and time according to |
| 52 |
/// some external reference. |
| 53 |
/// |
| 54 |
/// External references may be reset, so this clock is not necessarily |
| 55 |
/// monotonic, making it unsuitable for measuring elapsed time. |
| 56 |
/// |
| 57 |
/// It is intended for reporting the current date and time for humans. |
| 58 |
interface wall-clock { |
| 59 |
/// A time and date in seconds plus nanoseconds. |
| 60 |
record datetime { |
| 61 |
seconds: u64, |
| 62 |
nanoseconds: u32, |
| 63 |
} |
| 64 |
|
| 65 |
/// Read the current value of the clock. |
| 66 |
/// |
| 67 |
/// This clock is not monotonic, therefore calling this function repeatedly |
| 68 |
/// will not necessarily produce a sequence of non-decreasing values. |
| 69 |
/// |
| 70 |
/// The returned timestamps represent the number of seconds since |
| 71 |
/// 1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch], |
| 72 |
/// also known as [Unix Time]. |
| 73 |
/// |
| 74 |
/// The nanoseconds field of the output is always less than 1000000000. |
| 75 |
/// |
| 76 |
/// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16 |
| 77 |
/// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time |
| 78 |
now: func() -> datetime; |
| 79 |
|
| 80 |
/// Query the resolution of the clock. |
| 81 |
/// |
| 82 |
/// The nanoseconds field of the output is always less than 1000000000. |
| 83 |
resolution: func() -> datetime; |
| 84 |
} |
| 85 |
|
| 86 |
world imports { |
| 87 |
import wasi:io/[email protected]; |
| 88 |
import monotonic-clock; |
| 89 |
import wall-clock; |
| 90 |
} |