Add ability to hook/wrap an EventLoop. #1858
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've been thinking about how to get wgpu to integrate into the winit event loop (specifically to avoid needing users to continually call
device.poll
in order for gpu buffers to actually get mapped).Anyhow, there were two ways of doing this:
device.poll
once per frame.The second option seemed preferable to me. Another issue is that, if
control_flow
is set toWait
, the event handler will only be called if the user interacts. That's not good enough in this case, so the hook wraps the user-specified event handler so it can detect if the handler set the control flow toWait
and change it toWaitUntil
or similar instead.The main things added are the
Hook
trait andEventLoop::set_hook
.EventLoop::set_hook
actually consumes theEventLoop
and returns a new type ofEventLoop<T, H>
, whereH: Hook<T>
.