Initialize the thread pool in JavaScript
mainAfter adding the dependency, you must re-export init_thread_pool from your Rust code. This exposes an async initThreadPool function in your generated JavaScript.
You must call initThreadPool on the main thread immediately after the standard wasm-bindgen initialization and before calling any functions that require concurrency.
// In your Rust code
pub use wasm_bindgen_rayon::init_thread_pool;import init, { initThreadPool /* ... */ } from './pkg/index.js';
// Regular wasm-bindgen initialization.
await init();
// Thread pool initialization with the given number of threads
// (pass `navigator.hardwareConcurrency` if you want to use all cores).
await initThreadPool(navigator.hardwareConcurrency);
// ...now you can invoke any exported functions as you normally would