-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add EventLoopProxy::waker(self) -> Waker
#3424
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
base: master
Are you sure you want to change the base?
Conversation
87c7468 to
2c6aba9
Compare
This comment was marked as resolved.
This comment was marked as resolved.
EventLoop::waker(&self) -> WakerEventLoopProxy::waker(self) -> Waker
78cd1d5 to
28f339f
Compare
dhardy
left a comment
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.
I support this change: it makes winit simpler (at least at the API level).
Also, even though I currently use UserEvent, half the reason for that is just to create a Waker over it.
src/event_loop.rs
Outdated
| // Note: This does not have the generic from `EventLoopProxy<T>`, since this | ||
| // is the new API that shouldn't need it. | ||
| impl From<EventLoopProxy> for Waker { | ||
| fn from(proxy: EventLoopProxy) -> Self { | ||
| proxy.waker() | ||
| } | ||
| } |
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.
I'm not sure this is wanted — eventually EventLoopProxy will (presumably) just be replaced with a Waker.
In fact, maybe just deprecate EventLoopProxy and create_proxy now, replacing with EventLoop::create_waker?
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.
I want to reuse proxy in the future for some internal stuff in the future around Send/Sync and also, not be limited on the Waker API, since it's rather limited. But yeah, in the current state they are mostly the same.
|
We're doing this with custom code in Dioxus. It would definitely be nice to have in Winit. |
No: the only purpose of waker is to awaken the event-loop. The current changes to winit (since v0.30) already force sending of user payloads through something like an FYI I updated Kas to use winit last week in this PR: kas-gui/kas#583. You can also see my own |
As part of #3367, we're considering removing the generic on
Event<T>,EventLoop<T>,EventLoopProxy<T>and the callback. By extension, we'd be getting rid ofEvent::UserEvent(T).One approach to doing so would be to allow converting
EventLoopProxyto the standard library'sWakertype, which allows the user to wake a task (in this case the event loop) from any thread; then they can implement what they need themselves on top of that, using the standard library'smpsc::channel,mpsc::sync_channelor likewise, depending on their needs.This is likely not a perfect solution for wakeups, we still need to properly figure out how to do timers; but this can get us some of the way there.
Blocked on #3449, we need to ensure that
Syncis actually sound.CC @notgull, I think this may be slightly useful for
async?Questions:
UserWokenevent, or isNewEventsis enough?Wakerbehind a custom type likeEventLoopWaker, in case we want to expose further functionality in the future?EventLoopProxy, and allow that to be converted toWaker.Wakertoo heavy-weight for this? Can we just use a functionwake(&self)onEventLoopProxy? Or maybe both?mpsc?TODO:
Wakerimplementations with updated example.CHANGELOG.md.