Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename poll-list to poll, poll-one to pollable.block, and introduce pollable.ready #7427

Merged
merged 9 commits into from
Oct 31, 2023

Conversation

pchickey
Copy link
Contributor

Downstreaming changes to wasi:io/poll proposed here:
WebAssembly/wasi-io#54

poll-list becomes poll and poll-one becomes a method directly on pollable - these are NFCs, just renamings for ergonomics, and because poll-one was easily confused with poll-oneoff.

pollable.ready is new functionality that allows you to check the readiness of a pollable without blocking. I took the most trivial path to implement it via futures::poll_immediate. I had to add a minor optimization to the clock deadline future so that we can test it by asserting subscribe_duration(0).ready() and subscribe_instant(now() - 1).ready() are true.

Pat Hickey added 8 commits October 31, 2023 10:14
* move contents of Host::poll_one to HostPollable::block
* rename Host::poll_list to Host::poll,
* implement HostPollable::ready, using futures::future::poll_immediate
this is an optimization, but what it really allows us to do is assert
pollable.ready() for a subscribe_duration(0) is ready immediately.
test-programs/src/bin/preview2_sleep.rs in particular now asserts
ready() on a subscribe_duration(0) and a subscribe_instant(now() - 1),
so we have test coverage for ready as well now
@pchickey pchickey requested a review from a team as a code owner October 31, 2023 18:00
@pchickey pchickey requested review from alexcrichton and removed request for a team October 31, 2023 18:00
@github-actions github-actions bot added the wasi Issues pertaining to WASI label Oct 31, 2023
"poll-one",
"poll",
"[method]pollable.block",
"[method]pollable.ready",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this method wouldn't be on this list since it shouldn't block, but I can also see how that complicates the implementation, so I'm fine either way

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. The implementation, as it stands, shouldn't ever actually be Pending, and I think we will be able to keep an eye on that invariant going forwards.

let pollable = table.get(&pollable)?;
let ready = (pollable.make_future)(table.get_any_mut(pollable.index)?);
futures::pin_mut!(ready);
Ok(futures::future::poll_immediate(ready).await.is_some())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this perhaps be matches!(..., Some(())) to emphasize this isn't accidentally throwing away a "real" result from the poll?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

Co-authored-by: Alex Crichton <alex@alexcrichton.com>
@pchickey pchickey added this pull request to the merge queue Oct 31, 2023
Merged via the queue into main with commit ddffc7e Oct 31, 2023
20 checks passed
@pchickey pchickey deleted the pch/pollable_methods branch October 31, 2023 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasi Issues pertaining to WASI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants