-
Notifications
You must be signed in to change notification settings - Fork 117
feat(event streaming): configurable worker path, use SharedWorker #2080
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
e97d49c
44052d4
41c8a83
f9ca486
0682dd1
0476609
50e8f74
4955bf4
d6120f3
a161ada
9bb1e8a
5f015f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| use mm2_core::mm_ctx::MmArc; | ||
| use serde_json::json; | ||
|
|
||
| const DEFAULT_WORKER_PATH: &str = "worker.js"; | ||
|
|
||
| /// Handles broadcasted messages from `mm2_event_stream` continuously for WASM. | ||
| pub async fn handle_worker_stream(ctx: MmArc) { | ||
| let config = ctx | ||
|
|
@@ -17,7 +19,8 @@ pub async fn handle_worker_stream(ctx: MmArc) { | |
| "message": event.message(), | ||
| }); | ||
|
|
||
| let worker = web_sys::Worker::new("worker.js").expect("Missing worker.js"); | ||
| let worker_path = config.worker_path.as_deref().unwrap_or(DEFAULT_WORKER_PATH); | ||
| let worker = web_sys::Worker::new(worker_path).expect("Missing worker.js"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might not be "worker.js".
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was already fixing this. Done :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we might have another Also,
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I left it as
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can make it
Can you please elaborate on this @borngraced ?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It's still a single worker file for event streaming
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If they requested multiple workers in the future we can do it in another PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It's just for demonstration, it doesn't have to be that way obviously. You can handle all kinds of operations from a single worker file by filtering the incoming payload. As I mentioned, this preference should be defined by the frontend developers not by us as this affects their project structure directly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I am aware of it, I meant event streaming + different tasks on workers
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In this case they can change the config I guess. |
||
| let message_js = wasm_bindgen::JsValue::from_str(&data.to_string()); | ||
|
|
||
| worker.post_message(&message_js) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.