-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use web workers to load the route snapper. #23
... doesn't work, we can't ship a WASM thing across the web worker channels
- Loading branch information
1 parent
7879dd2
commit 753bfb9
Showing
4 changed files
with
33 additions
and
16 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,25 @@ | ||
importScripts("./pkg/route_snapper.js"); | ||
|
||
console.log("Hi from worker"); | ||
|
||
// Weird workaround to make WASM work in web workers. See | ||
// https://rustwasm.github.io/wasm-bindgen/examples/wasm-in-web-worker.html | ||
const { JsRouteSnapper } = wasm_bindgen; | ||
async function setup() { | ||
console.log("Hi from setup"); | ||
await wasm_bindgen("./pkg/route_snapper_bg.wasm"); | ||
console.log("setup done"); | ||
} | ||
//setup(); | ||
|
||
// Web worker magic | ||
self.onmessage = async (e) => { | ||
console.log("got msg"); | ||
await setup(); | ||
console.log("now doing stuff"); | ||
console.time("Deserialize and setup JsRouteSnapper"); | ||
const inner = new JsRouteSnapper(e.data); | ||
console.log("cool done, now pass it back"); | ||
console.timeEnd("Deserialize and setup JsRouteSnapper"); | ||
self.postMessage(inner); | ||
}; |
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