-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Conversation
* 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
"poll-one", | ||
"poll", | ||
"[method]pollable.block", | ||
"[method]pollable.ready", |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
crates/wasi/src/preview2/poll.rs
Outdated
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()) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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>
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()
andsubscribe_instant(now() - 1).ready()
are true.