# CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
## Build & Development Commands
**Format (nightly):**
```bash
cargo +nightly fmt --all -- --check
```
**Lint (nightly):**
```bash
cargo +nightly clippy --all-features
```
**Doc tests:**
```bash
cargo test --doc
```
**Integration tests (requires wasm-pack and npm):**
```bash
cd test && npm ci && npm test
```
**Build WASM for testing:**
```bash
cd test && npm run build:web
```
## Architecture Overview
`wasmworker` parallelizes tasks on WebAssembly without requiring SharedArrayBuffer. It uses message passing with postcard serialization instead of shared memory.
**Workspace structure (4 crates):**
- `wasmworker/` - Main library with worker management, pool, and iterator extensions
- `wasmworker-proc-macro/` - The `#[webworker_fn]` procedural macro
- `test/` - Integration tests using wasm-pack and Playwright
- `demo/` - Example usage
**Core modules in `src/`:**
- `webworker/worker.rs` - Single WebWorker instance management
- `webworker/com.rs` - Request/Response message types
- `webworker/js.rs` - JavaScript blob for worker initialization
- `pool/mod.rs` - WebWorkerPool (multiple workers)
- `pool/scheduler.rs` - RoundRobin and LoadBased scheduling strategies
- `global.rs` - Singleton worker pool via `tokio::sync::OnceCell`
- `iter_ext/mod.rs` - `par_map` and `try_par_map` iterator extensions
- `func.rs` - `WebWorkerFn` type and `webworker!()` macro
- `convert.rs` - Serialization wrappers using postcard
**Communication flow:**
1. Main thread sends `Request(id, func_name, serialized_arg)` to worker
2. Worker executes function, sends back `Response(id, serialized_result)`
3. Worker initialization: JS blob loads WASM module, imports function exports
**Key patterns:**
- Functions must be annotated with `#[webworker_fn]` from the proc-macro crate
- Use `webworker!(func_name)` macro to get type-safe `WebWorkerFn<T, R>` handle
- All task arguments/returns must implement `serde::Serialize + Deserialize`
- Target is `wasm-bindgen --target web`