-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wasm): Run Lumina in a Shared Worker (#265)
This PR introduces several features: either SharedWorker or Worker is spawned for the lumina instance, so that we no longer run in main "GUI" thread. NodeDriver replaces WasmNode and is responsible for steering actual lumina node running inside a Worker. Multiple tabs from the same context can access the same lumina instance. After spawning the shared worker, NodeDriver establishes a request-response communication channel over JS primitives. Node inside the SharedWorker has server-like infrastructure. onconnect event means that a new connection happened and we're supposed to use event.port[0] to communicate with a newly connected NodeDriver by responding with results of the command we're sent. Node inside Worker has simplified architecture, since it doesn't need to handle new tabs connecting, but otherwise works the same --------- Signed-off-by: Mikołaj Florkiewicz <[email protected]> Co-authored-by: Yiannis Marangos <[email protected]> Co-authored-by: Maciej Zwoliński <[email protected]>
- Loading branch information
1 parent
d00e97a
commit e932d3e
Showing
15 changed files
with
1,234 additions
and
224 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,29 @@ | ||
// this file will be installed by wasm-pack in pkg/snippets/<pkg-name>-<hash>/js/ | ||
import init, { run_worker } from '../../../lumina_node_wasm.js'; | ||
|
||
// get the path to this file | ||
export function worker_script_url() { | ||
return import.meta.url; | ||
} | ||
|
||
// if we are in a worker | ||
if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) { | ||
Error.stackTraceLimit = 99; | ||
|
||
// for SharedWorker we queue incoming connections | ||
// for dedicated Worker we queue incoming messages (coming from the single client) | ||
let queued = []; | ||
if (typeof SharedWorkerGlobalScope !== 'undefined' && self instanceof SharedWorkerGlobalScope) { | ||
onconnect = (event) => { | ||
queued.push(event) | ||
} | ||
} else { | ||
onmessage = (event) => { | ||
queued.push(event); | ||
} | ||
} | ||
|
||
await init(); | ||
console.log("starting worker, queued messages: ", queued.length); | ||
await run_worker(queued); | ||
} |
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 |
---|---|---|
|
@@ -4,4 +4,5 @@ | |
pub mod error; | ||
pub mod node; | ||
pub mod utils; | ||
mod worker; | ||
mod wrapper; |
Oops, something went wrong.