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
Gloo Workers v2 #214
Merged
Merged
Gloo Workers v2 #214
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0f4dded
Add First Webworker
droogmic 5efd34e
Web Workers
droogmic 9e2c7f9
Merge branch 'main' into web_workers
droogmic 75f7e37
Add Reproduction Test
droogmic ec38a72
Use Gloo Workers v2
droogmic 5f6e7f0
WIP
droogmic f1eff7d
Check Upstream
droogmic b6158c9
Get It Working
droogmic bfcd7cd
rebase
droogmic 5252930
Rework
droogmic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was motivated by tracking down where the serde flattening bug was happening, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, if you replace this with bincode, the test fails :)