web: Add EventLoop::spawn (#2208)
* web: Add `EventLoop::spawn` This is the same as `EventLoop::run`, but doesn't throw an exception in order to return `!`. I decided to name it `spawn` rather than `run_web` because I think that's more descriptive, but I'm happy to change it to `run_web`. Resolves #1714 * Update src/platform/web.rs Co-authored-by: Markus Røyset <maroider@protonmail.com> * Fix outdated names Co-authored-by: Markus Røyset <maroider@protonmail.com>
This commit is contained in:
parent
cdd9b1e1eb
commit
aa8f8db305
3 changed files with 56 additions and 9 deletions
|
|
@ -29,7 +29,22 @@ impl<T> EventLoop<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn run<F>(self, mut event_handler: F) -> !
|
||||
pub fn run<F>(self, event_handler: F) -> !
|
||||
where
|
||||
F: 'static + FnMut(Event<'_, T>, &RootEventLoopWindowTarget<T>, &mut ControlFlow),
|
||||
{
|
||||
self.spawn(event_handler);
|
||||
|
||||
// Throw an exception to break out of Rust execution and use unreachable to tell the
|
||||
// compiler this function won't return, giving it a return type of '!'
|
||||
backend::throw(
|
||||
"Using exceptions for control flow, don't mind me. This isn't actually an error!",
|
||||
);
|
||||
|
||||
unreachable!();
|
||||
}
|
||||
|
||||
pub fn spawn<F>(self, mut event_handler: F)
|
||||
where
|
||||
F: 'static + FnMut(Event<'_, T>, &RootEventLoopWindowTarget<T>, &mut ControlFlow),
|
||||
{
|
||||
|
|
@ -41,14 +56,6 @@ impl<T> EventLoop<T> {
|
|||
self.elw.p.run(Box::new(move |event, flow| {
|
||||
event_handler(event, &target, flow)
|
||||
}));
|
||||
|
||||
// Throw an exception to break out of Rust exceution and use unreachable to tell the
|
||||
// compiler this function won't return, giving it a return type of '!'
|
||||
backend::throw(
|
||||
"Using exceptions for control flow, don't mind me. This isn't actually an error!",
|
||||
);
|
||||
|
||||
unreachable!();
|
||||
}
|
||||
|
||||
pub fn create_proxy(&self) -> EventLoopProxy<T> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue