-
Notifications
You must be signed in to change notification settings - Fork 232
Add standalone waker constructor for executor and expose it #1015
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
Conversation
Hi! Thanks for the PR. Can you motivate the need for this a bit more? As I see it, and e.g. what async fn do_something() {
poll_fn(|cx| {
smoltcp.register_waker(cx.waker());
if smoltcp.api_that_later_will_wake().is_done_or_something() {
Poll::Ready(())
} else {
Poll::Pending
}
}).await
} |
Sometimes I need to wake other task than the one setting the waker, or with some other logic. So I would need to create the waker with poll_fn and store it somewhere, then retrieve with other methods. And it can't be done in const contexts. With that change code is very straightforward by directly using the waker for a task. So yes, it is possible, for non-const use cases, to use |
@korken89 is this motivation enough? This allows to not require a poll and not store a waker somewhere if you are not using it directly inside, as |
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.
It's no big addition, I'll add it. 👍
@Ddystopia can you fix the conflicts and I'll merge? |
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.
Rebased and moved changelog entries to Unreleased (releases happened) :)
Thanks!
Currently we can spawn a task with
task::spawn()
, but there is no way to get a waker. This PR adds const functiontask::waker()
, that returns a waker that will wake that task.My use case for this is smoltcp, they expose a lot of functions like that one: Socket::register_waker