pub async fn new() -> (
            EngineWorker<MW, WM>,
            futures::channel::mpsc::UnboundedReceiver<MW>,
        ) {
            let scope = utils::get_worker_global_context();

            let (fs, fr) = futures::channel::oneshot::channel();
            let mut fs = Some(fs);

            let (bags, bagf) = futures::channel::mpsc::unbounded();

            let _handle = gloo::events::EventListener::new(&scope, "message", move |event| {
                let event = event.dyn_ref::<web_sys::MessageEvent>().unwrap_throw();
                let data = event.data();

                let data: js_sys::Array = data.dyn_into().unwrap_throw();
                let offscreen = data.get(0);
                let payload = data.get(1);

                if !offscreen.is_null() {
                    let offscreen: web_sys::OffscreenCanvas = offscreen.dyn_into().unwrap_throw();
                    if let Some(fs) = fs.take() {
                        fs.send(offscreen).unwrap_throw();
                    }
                }

                if !payload.is_null() {
                    let e = payload.into_serde().unwrap_throw();
                    bags.unbounded_send(e).unwrap_throw();
                }
            });

            let data = js_sys::Array::new();
            data.set(0, JsValue::from_str("ready"));
            data.set(1, JsValue::null());

            scope.post_message(&data).unwrap_throw();

            let canvas = fr.await.unwrap_throw();

            (
                EngineWorker {
                    _handle,
                    canvas,
                    _p: PhantomData,
                },
                bagf,
            )
        }
///
/// Create the worker component of the engine.
/// Specify the frame rate.
/// Blocks until it receives the offscreen canvas from the main thread.
///
Create the worker component of the engine.
Specify the frame rate.
Blocks until it receives the offscreen canvas from the main thread.
Create the worker component of the engine . Specify the frame rate . Blocks until it receives the offscreen canvas from the main thread .
pub async fn new() -> (
            EngineWorker<MW, WM>,
            futures::channel::mpsc::UnboundedReceiver<MW>,
        ) {
            let scope = utils::get_worker_global_context();
            let (fs, fr) = futures::channel::oneshot::channel();
            let mut fs = Some(fs);
            let (bags, bagf) = futures::channel::mpsc::unbounded();
            let _handle = gloo::events::EventListener::new(&scope, "message", move |event| {
                let event = event.dyn_ref::<web_sys::MessageEvent>().unwrap_throw();
                let data = event.data();
                let data: js_sys::Array = data.dyn_into().unwrap_throw();
                let offscreen = data.get(0);
                let payload = data.get(1);
                if !offscreen.is_null() {
                    let offscreen: web_sys::OffscreenCanvas = offscreen.dyn_into().unwrap_throw();
                    if let Some(fs) = fs.take() {
                        fs.send(offscreen).unwrap_throw();
                    }
                }
                if !payload.is_null() {
                    let e = payload.into_serde().unwrap_throw();
                    bags.unbounded_send(e).unwrap_throw();
                }
            });
            let data = js_sys::Array::new();
            data.set(0, JsValue::from_str("ready"));
            data.set(1, JsValue::null());
            scope.post_message(&data).unwrap_throw();
            let canvas = fr.await.unwrap_throw();
            (
                EngineWorker {
                    _handle,
                    canvas,
                    _p: PhantomData,
                },
                bagf,
            )
        }
pub async fn new ( ) -> ( EngineWorker < MW , WM > , futures :: channel :: mpsc :: UnboundedReceiver < MW > , ) { let scope = utils :: get_worker_global_context ( ) ; let ( fs , fr ) = futures :: channel :: oneshot :: channel ( ) ; let mut fs = Some ( fs ) ; let ( bags , bagf ) = futures :: channel :: mpsc :: unbounded ( ) ; let _handle = gloo :: events :: EventListener :: new ( & scope , " " , move | event | { let event = event . dyn_ref :: < web_sys :: MessageEvent > ( ) . unwrap_throw ( ) ; let data = event . data ( ) ; let data : js_sys :: Array = data . dyn_into ( ) . unwrap_throw ( ) ; let offscreen = data . get ( 0 ) ; let payload = data . get ( 1 ) ; if ! offscreen . is_null ( ) { let offscreen : web_sys :: OffscreenCanvas = offscreen . dyn_into ( ) . unwrap_throw ( ) ; if let Some ( fs ) = fs . take ( ) { fs . send ( offscreen ) . unwrap_throw ( ) ; } } if ! payload . is_null ( ) { let e = payload . into_serde ( ) . unwrap_throw ( ) ; bags . unbounded_send ( e ) . unwrap_throw ( ) ; } } ) ; let data = js_sys :: Array :: new ( ) ; data . set ( 0 , JsValue :: from_str ( " " ) ) ; data . set ( 1 , JsValue :: null ( ) ) ; scope . post_message ( & data ) . unwrap_throw ( ) ; let canvas = fr . await . unwrap_throw ( ) ; ( EngineWorker { _handle , canvas , _p : PhantomData , } , bagf , ) }
Create the worker component of the engine.
Create the worker component of the engine .