Skip to content

Commit

Permalink
testdata/wasi: add wasi:clocks
Browse files Browse the repository at this point in the history
  • Loading branch information
ydnar committed Sep 21, 2023
1 parent bc3e465 commit 3305494
Show file tree
Hide file tree
Showing 4 changed files with 741 additions and 0 deletions.
363 changes: 363 additions & 0 deletions testdata/wasi/clocks.wit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,363 @@
{
"worlds": [
{
"name": "example-world",
"imports": {
"interface-0": {
"interface": 0
}
},
"exports": {},
"package": 0
},
{
"name": "imports",
"imports": {
"interface-0": {
"interface": 0
},
"interface-1": {
"interface": 1
},
"interface-2": {
"interface": 2
},
"interface-3": {
"interface": 3
}
},
"exports": {},
"package": 1
}
],
"interfaces": [
{
"name": "poll",
"types": {
"pollable": 0
},
"functions": {
"drop-pollable": {
"name": "drop-pollable",
"kind": "freestanding",
"params": [
{
"name": "this",
"type": 0
}
],
"results": [],
"docs": {
"contents": "Dispose of the specified `pollable`, after which it may no longer\nbe used."
}
},
"poll-oneoff": {
"name": "poll-oneoff",
"kind": "freestanding",
"params": [
{
"name": "in",
"type": 1
}
],
"results": [
{
"type": 2
}
],
"docs": {
"contents": "Poll for completion on a set of pollables.\n\nThis function takes a list of pollables, which identify I/O sources of\ninterest, and waits until one or more of the events is ready for I/O.\n\nThe result `list<bool>` is the same length as the argument\n`list<pollable>`, and indicates the readiness of each corresponding\nelement in that list, with true indicating ready. A single call can\nreturn multiple true elements.\n\nA timeout can be implemented by adding a pollable from the\nwasi-clocks API to the list.\n\nThis function does not return a `result`; polling in itself does not\ndo any I/O so it doesn't fail. If any of the I/O sources identified by\nthe pollables has an error, it is indicated by marking the source as\nready in the `list<bool>`.\n\nThe \"oneoff\" in the name refers to the fact that this function must do a\nlinear scan through the entire list of subscriptions, which may be\ninefficient if the number is large and the same subscriptions are used\nmany times. In the future, this is expected to be obsoleted by the\ncomponent model async proposal, which will include a scalable waiting\nfacility."
}
}
},
"docs": {
"contents": "A poll API intended to let users wait for I/O events on multiple handles\nat once."
},
"package": 0
},
{
"name": "monotonic-clock",
"types": {
"pollable": 3,
"instant": 4
},
"functions": {
"now": {
"name": "now",
"kind": "freestanding",
"params": [],
"results": [
{
"type": 4
}
],
"docs": {
"contents": "Read the current value of the clock.\n\nThe clock is monotonic, therefore calling this function repeatedly will\nproduce a sequence of non-decreasing values."
}
},
"resolution": {
"name": "resolution",
"kind": "freestanding",
"params": [],
"results": [
{
"type": 4
}
],
"docs": {
"contents": "Query the resolution of the clock."
}
},
"subscribe": {
"name": "subscribe",
"kind": "freestanding",
"params": [
{
"name": "when",
"type": 4
},
{
"name": "absolute",
"type": "bool"
}
],
"results": [
{
"type": 3
}
],
"docs": {
"contents": "Create a `pollable` which will resolve once the specified time has been\nreached."
}
}
},
"docs": {
"contents": "WASI Monotonic Clock is a clock API intended to let users measure elapsed\ntime.\n\nIt is intended to be portable at least between Unix-family platforms and\nWindows.\n\nA monotonic clock is a clock which has an unspecified initial value, and\nsuccessive reads of the clock will produce non-decreasing values.\n\nIt is intended for measuring elapsed time."
},
"package": 1
},
{
"name": "wall-clock",
"types": {
"datetime": 5
},
"functions": {
"now": {
"name": "now",
"kind": "freestanding",
"params": [],
"results": [
{
"type": 5
}
],
"docs": {
"contents": "Read the current value of the clock.\n\nThis clock is not monotonic, therefore calling this function repeatedly\nwill not necessarily produce a sequence of non-decreasing values.\n\nThe returned timestamps represent the number of seconds since\n1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch],\nalso known as [Unix Time].\n\nThe nanoseconds field of the output is always less than 1000000000.\n\n[POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16\n[Unix Time]: https://en.wikipedia.org/wiki/Unix_time"
}
},
"resolution": {
"name": "resolution",
"kind": "freestanding",
"params": [],
"results": [
{
"type": 5
}
],
"docs": {
"contents": "Query the resolution of the clock.\n\nThe nanoseconds field of the output is always less than 1000000000."
}
}
},
"docs": {
"contents": "WASI Wall Clock is a clock API intended to let users query the current\ntime. The name \"wall\" makes an analogy to a \"clock on the wall\", which\nis not necessarily monotonic as it may be reset.\n\nIt is intended to be portable at least between Unix-family platforms and\nWindows.\n\nA wall clock is a clock which measures the date and time according to\nsome external reference.\n\nExternal references may be reset, so this clock is not necessarily\nmonotonic, making it unsuitable for measuring elapsed time.\n\nIt is intended for reporting the current date and time for humans."
},
"package": 1
},
{
"name": "timezone",
"types": {
"datetime": 6,
"timezone-display": 7
},
"functions": {
"display": {
"name": "display",
"kind": "freestanding",
"params": [
{
"name": "when",
"type": 6
}
],
"results": [
{
"type": 7
}
],
"docs": {
"contents": "Return information needed to display the given `datetime`. This includes\nthe UTC offset, the time zone name, and a flag indicating whether\ndaylight saving time is active.\n\nIf the timezone cannot be determined for the given `datetime`, return a\n`timezone-display` for `UTC` with a `utc-offset` of 0 and no daylight\nsaving time."
}
},
"utc-offset": {
"name": "utc-offset",
"kind": "freestanding",
"params": [
{
"name": "when",
"type": 6
}
],
"results": [
{
"type": "s32"
}
],
"docs": {
"contents": "The same as `display`, but only return the UTC offset."
}
}
},
"package": 1
}
],
"types": [
{
"name": "pollable",
"kind": {
"type": "u32"
},
"owner": {
"interface": 0
},
"docs": {
"contents": "A \"pollable\" handle.\n\nThis is conceptually represents a `stream<_, _>`, or in other words,\na stream that one can wait on, repeatedly, but which does not itself\nproduce any data. It's temporary scaffolding until component-model's\nasync features are ready.\n\nAnd at present, it is a `u32` instead of being an actual handle, until\nthe wit-bindgen implementation of handles and resources is ready.\n\n`pollable` lifetimes are not automatically managed. Users must ensure\nthat they do not outlive the resource they reference.\n\nThis [represents a resource](https://github.com/WebAssembly/WASI/blob/main/docs/WitInWasi.md#Resources)."
}
},
{
"name": null,
"kind": {
"list": 0
},
"owner": null
},
{
"name": null,
"kind": {
"list": "bool"
},
"owner": null
},
{
"name": "pollable",
"kind": {
"type": 0
},
"owner": {
"interface": 1
}
},
{
"name": "instant",
"kind": {
"type": "u64"
},
"owner": {
"interface": 1
},
"docs": {
"contents": "A timestamp in nanoseconds."
}
},
{
"name": "datetime",
"kind": {
"record": {
"fields": [
{
"name": "seconds",
"type": "u64"
},
{
"name": "nanoseconds",
"type": "u32"
}
]
}
},
"owner": {
"interface": 2
},
"docs": {
"contents": "A time and date in seconds plus nanoseconds."
}
},
{
"name": "datetime",
"kind": {
"type": 5
},
"owner": {
"interface": 3
}
},
{
"name": "timezone-display",
"kind": {
"record": {
"fields": [
{
"name": "utc-offset",
"type": "s32",
"docs": {
"contents": "The number of seconds difference between UTC time and the local\ntime of the timezone.\n\nThe returned value will always be less than 86400 which is the\nnumber of seconds in a day (24*60*60).\n\nIn implementations that do not expose an actual time zone, this\nshould return 0."
}
},
{
"name": "name",
"type": "string",
"docs": {
"contents": "The abbreviated name of the timezone to display to a user. The name\n`UTC` indicates Coordinated Universal Time. Otherwise, this should\nreference local standards for the name of the time zone.\n\nIn implementations that do not expose an actual time zone, this\nshould be the string `UTC`.\n\nIn time zones that do not have an applicable name, a formatted\nrepresentation of the UTC offset may be returned, such as `-04:00`."
}
},
{
"name": "in-daylight-saving-time",
"type": "bool",
"docs": {
"contents": "Whether daylight saving time is active.\n\nIn implementations that do not expose an actual time zone, this\nshould return false."
}
}
]
}
},
"owner": {
"interface": 3
},
"docs": {
"contents": "Information useful for displaying the timezone of a specific `datetime`.\n\nThis information may vary within a single `timezone` to reflect daylight\nsaving time adjustments."
}
}
],
"packages": [
{
"name": "wasi:poll",
"interfaces": {
"poll": 0
},
"worlds": {
"example-world": 0
}
},
{
"name": "wasi:clocks",
"interfaces": {
"monotonic-clock": 1,
"wall-clock": 2,
"timezone": 3
},
"worlds": {
"imports": 1
}
}
]
}
Loading

0 comments on commit 3305494

Please sign in to comment.