-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(node-wasm)!: Add
stop()
in NodeClient
- Loading branch information
Showing
14 changed files
with
187 additions
and
181 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
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,20 @@ | ||
// Equivalent to `../../node-wasm/js/index.js` but loads `/wasm/lumina_node_wasm.js` | ||
|
||
import init, { NodeClient } from "/wasm/lumina_node_wasm.js" | ||
|
||
/** | ||
* Spawn a worker running lumina node and get the `NodeClient` connected to it. | ||
*/ | ||
export async function spawnNode() { | ||
await init(); | ||
let worker = new Worker(new URL("/js/worker.js", import.meta.url), { type: 'module' }); | ||
let client = await new NodeClient(worker); | ||
|
||
// Workaround | ||
await (new Promise(resolve => setTimeout(resolve, 500))); | ||
|
||
return client; | ||
} | ||
|
||
export * from "/wasm/lumina_node_wasm.js"; | ||
export default init; |
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 |
---|---|---|
@@ -1,21 +1,12 @@ | ||
import init, { run_worker } from '/wasm/lumina_node_wasm.js'; | ||
// Equivalent to `../../node-wasm/js/worker.js` but loads `/wasm/lumina_node_wasm.js` | ||
|
||
import init, { NodeWorker } from "/wasm/lumina_node_wasm.js"; | ||
|
||
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); | ||
} | ||
} | ||
init().then(async () => { | ||
let worker = new NodeWorker(self); | ||
console.log("starting worker: ", worker); | ||
|
||
init().then(() => { | ||
console.log("starting worker, queued messages: ", queued.length); | ||
run_worker(queued); | ||
}) | ||
await worker.run(); | ||
}); |
Oops, something went wrong.