Skip to content

Commit

Permalink
Replace EventLoop::run with EventLoop::spawn (#73)
Browse files Browse the repository at this point in the history
spawn event loop instead of using js exception control flow hack

essentially removes this, but now you have to remember to return control
flow to the browser because single threading async stuff (e.g. dont do
blocking stuff without using workers)

![image](https://github.com/Inochi2D/inox2d/assets/46694241/f7ba12cb-04a7-48b0-9d17-878ad98c0454)
  • Loading branch information
Speykious authored Jan 31, 2024
2 parents f2225c9 + 568f03c commit 1c28b09
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions examples/render-webgl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ async fn run() -> Result<(), Box<dyn std::error::Error>> {
use wasm_bindgen::prelude::Closure;
use wasm_bindgen::JsCast;
use winit::event::{Event, WindowEvent};
use winit::platform::web::EventLoopExtWebSys;

use crate::scene::WasmSceneController;

Expand Down Expand Up @@ -134,7 +135,7 @@ async fn run() -> Result<(), Box<dyn std::error::Error>> {
}

// Event loop
events.run(move |event, elwt| {
events.spawn(move |event, elwt| {
// it needs to be present
let _window = &window;
elwt.set_control_flow(winit::event_loop::ControlFlow::Wait);
Expand All @@ -156,7 +157,8 @@ async fn run() -> Result<(), Box<dyn std::error::Error>> {
}
_ => (),
}
})?;
});

Ok(())
}

Expand Down

0 comments on commit 1c28b09

Please sign in to comment.