This repository has been archived by the owner on Mar 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add First Webworker * Web Workers An attempt was made * Add Reproduction Test * Use Gloo Workers v2 * Check Upstream * Get It Working * Rework
- Loading branch information
Showing
9 changed files
with
144 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use gloo_worker::{Codec, HandlerId, Worker, WorkerScope}; | ||
use osm2lanes::test::{get_tests, TestCase}; | ||
use serde::{Deserialize, Serialize}; | ||
use wasm_bindgen::JsValue; | ||
|
||
pub struct JsonCodec; | ||
|
||
impl Codec for JsonCodec { | ||
fn encode<I>(input: I) -> JsValue | ||
where | ||
I: Serialize, | ||
{ | ||
let data = serde_json::to_string(&input).expect("can't serialize worker message"); | ||
log::trace!("message in: {data}"); | ||
JsValue::from_str(&data) | ||
} | ||
|
||
fn decode<O>(input: JsValue) -> O | ||
where | ||
O: for<'de> Deserialize<'de>, | ||
{ | ||
let data = input.as_string().expect("JsValue string"); | ||
log::trace!("message out: {data}"); | ||
serde_json::from_str(&data).expect("can't deserialize worker message") | ||
} | ||
} | ||
|
||
pub(crate) const NAME: &str = "worker.js"; | ||
|
||
pub struct ExampleLoader; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct ExampleLoaderOutput(pub Vec<TestCase>); | ||
|
||
impl Worker for ExampleLoader { | ||
type Message = (); | ||
type Input = (); | ||
type Output = ExampleLoaderOutput; | ||
|
||
fn create(_scope: &WorkerScope<Self>) -> Self { | ||
Self | ||
} | ||
|
||
fn update(&mut self, _scope: &WorkerScope<Self>, _msg: Self::Message) { | ||
// no messaging | ||
} | ||
|
||
fn received(&mut self, scope: &WorkerScope<Self>, _msg: Self::Input, id: HandlerId) { | ||
let tests = get_tests(); | ||
let examples = tests | ||
.into_iter() | ||
.filter(|t| t.example().is_some()) | ||
.collect(); | ||
scope.respond(id, ExampleLoaderOutput(examples)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use osm2lanes_web::App; | ||
|
||
fn main() { | ||
console_error_panic_hook::set_once(); | ||
console_log::init_with_level(log::Level::Debug).expect("logging failed"); | ||
log::trace!("Initializing yew..."); | ||
yew::start_app::<App>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use gloo_worker::Registrable; | ||
use osm2lanes_web::agent::{ExampleLoader, JsonCodec}; | ||
|
||
fn main() { | ||
console_error_panic_hook::set_once(); | ||
console_log::init_with_level(log::Level::Debug).expect("logging failed"); | ||
log::trace!("Initializing worker..."); | ||
ExampleLoader::registrar() | ||
.encoding::<JsonCodec>() | ||
.register(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters