Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

Rename poll_oneoff to poll_list, add poll_one #22

Closed
sunfishcode opened this issue Aug 17, 2023 · 4 comments
Closed

Rename poll_oneoff to poll_list, add poll_one #22

sunfishcode opened this issue Aug 17, 2023 · 4 comments

Comments

@sunfishcode
Copy link
Member

The name "oneoff" was never very evocative, so I propose we rename it to poll_list because it polls a list of pollables.

Also, for convenience because it's a common case when writing simple examples and when compiling blocking code, I propose we add a poll_one function that just takes one pollable.

I'd ideally like to make these changes at the same time as converting to resources, to minimize churn in downstream users.

@lukewagner
Copy link
Member

On the topic of changing these APIs: in addition to renaming, I'd suggest returning a list-of-ready-indices (instead of a list-of-bools) and/or having a poll that takes a list and returns a single pollable index (avoiding list allocation in the common single-ready case).

@cpetig
Copy link

cpetig commented Aug 31, 2023

Wearing my functional safety hat I want to avoid all allocations at runtime, because they easily introduce unpredictable delays into the system (unless you replace the allocator with a more complex bounded time implementation).

So I wish there were also a non-allocating variant of this call, my proposal would be to add a non-allocating variant for the common up-to-64-pollables case:

poll_up_to64: func (in: list<pollable>) -> bitflags64

Of course this involves adding a way to express constant size list as bitflags.

(I am mostly concerned about the main loop of a service implementation where this function constantly polls which input stream to process next and might often return without a wait)

Update: Removed the borrow from the signature as it is default for imported functions.

@sunfishcode
Copy link
Member Author

In WebAssembly/wasi-io#46 I'm proposing to do the rename of poll-oneoff to poll-list and make it return a list of indices, and add poll-one.

I have not yet proposed any changes for the single-ready case. In any approach where we return fewer events than have actually occurred, an implementation would need to associate a buffer of pending events for each pollable, which would add some complexity, so I've chosen to defer that for now.

I also have not yet proposed any changes for poll-up-to64. My assumption is that with some work in the bindings, we can avoid actually performing a dynamic allocation, perhaps by maintaining a static buffer to be reused for poll calls. But if I'm wrong, it'd likely be easy to add this.

sunfishcode added a commit to sunfishcode/wasi-io that referenced this issue Sep 12, 2023
 - 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.
sunfishcode added a commit to WebAssembly/wasi-io that referenced this issue Sep 29, 2023
* 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.
@sunfishcode
Copy link
Member Author

WebAssembly/wasi-io#46 has renamed poll_oneoff to poll_list, and added a poll_one. I didn't yet add a poll_up_to64; feel free to file an issue in the wasi-io issue tracker to discuss this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants