jekirl / rust-shared-wasm-experiments

The example WASM library show casing shared HashMap, and crossbeam's channel between workers.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rust WASM experiment with shared memory

The example WASM library show cases Crossbeam Channels and shared HashMap usage between workers.

  1. Install wasm-pack
  2. Install deno for static File HTTP server, see file-server-deno.ts 1
  3. Run wasm-pack build
  4. Run deno run --allow-run --allow-net --allow-read file-server-deno.ts
  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. See index.js and worker.js for details.

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.

About

The example WASM library show casing shared HashMap, and crossbeam's channel between workers.

License:MIT License


Languages

Language:JavaScript 51.8%Language:Rust 32.8%Language:TypeScript 10.5%Language:HTML 4.8%