we (web engine): Experimental web browser project to understand the limits of Claude
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

Web Worker thread infrastructure and message channels #177

open opened by pierrelf.com

Phase 19: Web Workers#

Lay the low-level foundation for Web Workers in the js crate.

What to implement#

  • Worker thread lifecycle: spawn a dedicated OS thread per Worker, park it on a run-loop waiting for work, and shut it down cleanly on terminate().
  • Message channel types: MessagePort (a typed wrapper around std::sync::mpsc) and MessageChannel (a pair of connected ports). Both ends must be sendable across threads.
  • WorkerHandle: an opaque struct held by the main thread that owns the send half of the channel and a JoinHandle. terminate() drops the sender (closing the channel) then joins the thread.
  • Inbound message queue on the worker thread: the run-loop drains the channel, executing pending messages, and yields back to JS execution when idle.
  • Thread-safe error propagation: worker-side panics/errors should be forwarded back to the main thread as an ErrorRecord so the JS binding layer can fire onerror.

Acceptance criteria#

  • A unit test spawns a worker thread, sends a string message, receives the echo on the main thread, then terminates cleanly.
  • No unsafe outside platform/crypto/js (std thread primitives are fine).
  • cargo test -p we-js passes.
sign up or login to add to the discussion
Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:meotu43t6usg4qdwzenk4s2t/sh.tangled.repo.issue/3mlxpnrpkmc2v