Skip to content

README: Worker (Worker step 5) - #84

Merged
ASDAlexander77 merged 1 commit into
mainfrom
worker-readme
Nov 9, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
worker-readme

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

What

Step 5 of docs/worker-design.md, the last one: a Worker<In, Out> section in the README, right after Thread.

It covers:

  • The API, in MDN's terms: new Worker(body, name?); self as a WorkerScope (postMessage, onmessage, close(), name); and on the creating side postMessage, onmessage and onerror, with MessageEvent and ErrorEvent.
  • What differs from a browser:
    • the worker is a function, not a script URL;
    • self is a parameter, not a global;
    • with no event loop, the program gets replies through receive(), dispatch() or join();
    • terminate() waits for a handler that's already running instead of killing it.
  • The rules:
    • every worker must be joined or terminated;
    • messages are handed over, not copied (JSON.stringify gives a copy);
    • a throw from a handler keeps the worker running, and a throw from body ends it;
    • with no onerror set, errors are written to stderr.
  • The two -mm=own limits on handlers:
    • a creating-side onmessage keeps its state in a Shared<T>;
    • once body captures anything from the creating thread, a worker handler can use that state or post with self, not both.
  • An example: I compiled and ran it under gc, rc, none and own. It prints squared: 1, squared: 4, squared: 9 each time, as the README says.

docs/worker-design.md now marks step 5 done and the design built.

CI

The CI matrix needed no change, because tests.ps1 and tests.sh run every file in tests/. CI on main has already run the worker tests on Windows and Ubuntu under every memory model, release and debug, and they passed. That covers the debug configuration, which couldn't be built locally.

🤖 Generated with Claude Code

A Worker<In, Out> entry after Thread: the API as MDN's Worker and
DedicatedWorkerGlobalScope, what differs here (a function, not a
script URL; self a parameter; receive / dispatch / join instead of an
event loop; terminate waits for a running handler), errors to onerror,
messages handed over rather than copied, join or terminate every
worker, and the two -mm=own limits on handlers. The example prints
"squared: 1", "squared: 4", "squared: 9" under gc, rc, none and own.

docs/worker-design.md marks step 5 done and the design built. The CI
matrix needed no change: tests.ps1 / tests.sh run every test, and CI
on main ran the worker tests on Windows and Ubuntu under every model,
release and debug.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit cf59120 into main Nov 9, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant