wasmyon

Experimental "turn key" solution for wasm and rayon. This pretty much copies the pool.rs from the official example, adding some stuff.

To see how to use this library, see the examples/simple/src/lib.rs. In essence all rayon calls must return a JS Promise to work correctly, so the API is:

```rust

[wasmyon_promise]

pub fn suminworkers() -> i32 { (0..100000 as i32).intopariter().sum::() } ```

This creates a JS wrapper function:

typescript function sum_in_workers() -> Promise<any>

Additionally, if you want to run something in a worker by yourself, you can do it like this:

rust run_in_worker(|| yourstuff)

Note Currently the library assumes your application is generated with wasm-pack using --out-name index. This is because there is no way to get import.meta.url in the WASM, this is a limitation in wasm-bindgen.

Try out the example

To test out, go to examples/simple directory and do the following:

  1. Install wasm-pack
  2. Install deno for static File HTTP server, see file-server-deno.ts 1
  3. Run wasm-pack build --target web --out-name index
  4. Run deno run --allow-run --allow-net --allow-read ../file-server-deno.ts simple
  5. Navigate to http://localhost:8000
  6. Open a DevTools to see the communication in console

How it works?

It initalizes only one WebAssembly.Memory object and shares it between the workers. It also creates the thread workers within wasm-bindgen JS snippet.

TODO

Footnotes

1: If you don't want Deno, you still need a file server that is capable of setting headers Cross-Origin-Opener-Policy: same-origin and Cross-Origin-Embedder-Policy: require-corp, otherwise SharedArrayBuffer is not defined. See documentation.