winit
winit copied to clipboard
Add `EventLoopProxy::waker(self) -> Waker`
As part of https://github.com/rust-windowing/winit/issues/3367, we're considering removing the generic on Event<T>
, EventLoop<T>
, EventLoopProxy<T>
and the callback. By extension, we'd be getting rid of Event::UserEvent(T)
.
One approach to doing so would be to allow converting EventLoopProxy
to the standard library's Waker
type, 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's mpsc::channel
, mpsc::sync_channel
or 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 https://github.com/rust-windowing/winit/pull/3449, we need to ensure that Sync
is actually sound.
CC @notgull, I think this may be slightly useful for async
?
Questions:
- [ ] Do we need a
UserWoken
event, or isNewEvents
is enough? - [x] Should we hide the
Waker
behind a custom type likeEventLoopWaker
, in case we want to expose further functionality in the future?- We keep
EventLoopProxy
, and allow that to be converted toWaker
.
- We keep
- [ ] Is
Waker
too heavy-weight for this? Can we just use a functionwake(&self)
onEventLoopProxy
? Or maybe both? - [ ] Does the user need the ability to handle the case where the event loop has been destroyed? Or is that handled fine enough through other means, like in
mpsc
?
TODO:
- [ ] Finish implementation on all platforms.
- [ ] Properly test
Waker
implementations with updated example. - [ ] Add an entry to
CHANGELOG.md
. - [ ] Update documentation.