Skip to content

Commit 1f37cec

Browse files
authored
Convert to Resources, and other API cleanups. (#46)
* Convert to Resources, and other API cleanups. - Convert to resources. Use resources instead of `u32`s, remove drop functions, `this` arguments, and rename `subscribe-to-*` to just `subscribe`, as discussed in WebAssembly/wasi-poll#21. - Merge wasi-poll into wasi-io. These two proposals are closely related to each other, so it makes sense to have them together. - While here, tidy up the poll API, incorporating ideas discussed in WebAssembly/wasi-poll#22: - Rename `poll-oneoff` to `poll-list`, and add a `poll-one`. - Change `poll-oneoff`'s return type from `list<bool>` to `list<u32>`, because in the common case, this should allow it to create much smaller allocations. * Update to WebAssembly/wit-abi-up-to-date@v14. * Remove the wit-deps check now that we have no dependencies. * Fix more references to `poll-oneoff`. * Mark `poll` arguments as borrowed. * Update to wit-abi-up-to-date@v15.
1 parent 4bf705c commit 1f37cec

File tree

11 files changed

+651
-728
lines changed

11 files changed

+651
-728
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,5 @@ jobs:
1010
name: Check ABI files are up-to-date
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v2
14-
- name: ensure `./wit/deps` are in sync
15-
run: |
16-
curl -Lo 'wit-deps' https://github.com/bytecodealliance/wit-deps/releases/download/v0.3.2/wit-deps-x86_64-unknown-linux-musl
17-
chmod +x wit-deps
18-
./wit-deps lock --check
19-
- uses: WebAssembly/wit-abi-up-to-date@v13
20-
with:
21-
wit-abi-tag: wit-abi-0.11.0
13+
- uses: actions/checkout@v3
14+
- uses: WebAssembly/wit-abi-up-to-date@v15

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ types, `input-stream`, and `output-stream`, which support `read` and
6969

7070
// If we didn't get any data promptly, wait for it.
7171
if data.len() == 0 {
72-
let _ = poll_oneoff(&wait_input[..]);
72+
let _ = poll_list(&wait_input[..]);
7373
(data, eos) = input.read(BUFFER_LEN)?;
7474
}
7575

@@ -79,7 +79,7 @@ types, `input-stream`, and `output-stream`, which support `read` and
7979

8080
// If we didn't put any data promptly, wait for it.
8181
if num_written == 0 {
82-
let _ = poll_oneoff(&wait_output[..]);
82+
let _ = poll_list(&wait_output[..]);
8383
num_written = output.write(remaining)?;
8484
}
8585

@@ -108,7 +108,7 @@ types, `input-stream`, and `output-stream`, which support `read` and
108108

109109
// If we didn't get any data promptly, wait for it.
110110
if num_copied == 0 {
111-
let _ = poll_oneoff(&wait_input[..]);
111+
let _ = poll_list(&wait_input[..]);
112112
}
113113
}
114114
Ok(())

example-world.md

Lines changed: 0 additions & 417 deletions
This file was deleted.

imports.md

Lines changed: 386 additions & 0 deletions
Large diffs are not rendered by default.

wit/deps.lock

Lines changed: 0 additions & 4 deletions
This file was deleted.

wit/deps.toml

Lines changed: 0 additions & 1 deletion
This file was deleted.

wit/deps/poll/poll.wit

Lines changed: 0 additions & 49 deletions
This file was deleted.

wit/deps/poll/world.wit

Lines changed: 0 additions & 5 deletions
This file was deleted.

wit/poll.wit

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package wasi:io
2+
3+
/// A poll API intended to let users wait for I/O events on multiple handles
4+
/// at once.
5+
interface poll {
6+
/// A "pollable" handle.
7+
resource pollable
8+
9+
/// Poll for completion on a set of pollables.
10+
///
11+
/// This function takes a list of pollables, which identify I/O sources of
12+
/// interest, and waits until one or more of the events is ready for I/O.
13+
///
14+
/// The result `list<u32>` contains one or more indices of handles in the
15+
/// argument list that is ready for I/O.
16+
///
17+
/// If the list contains more elements than can be indexed with a `u32`
18+
/// value, this function traps.
19+
///
20+
/// A timeout can be implemented by adding a pollable from the
21+
/// wasi-clocks API to the list.
22+
///
23+
/// This function does not return a `result`; polling in itself does not
24+
/// do any I/O so it doesn't fail. If any of the I/O sources identified by
25+
/// the pollables has an error, it is indicated by marking the source as
26+
/// being reaedy for I/O.
27+
poll-list: func(in: list<borrow<pollable>>) -> list<u32>
28+
29+
/// Poll for completion on a single pollable.
30+
///
31+
/// This function is similar to `poll-list`, but operates on only a single
32+
/// pollable. When it returns, the handle is ready for I/O.
33+
poll-one: func(in: borrow<pollable>)
34+
}

0 commit comments

Comments
 (0)