# Go Worker Lab

By Chason Arthur · Revision 126.014 · Published and updated November 3, 2026.

## Click and run locally

1. Extract this whole ZIP to a new directory.
2. Use Python 3.10 or later to run `python preview.py` from that directory.
3. Open the loopback URL printed by the preview.
4. Click Run this example. Use Reset to stop and clear the environment.
5. View the code, follow the tutorial, and compare the two implementations.
6. Stop the preview with Ctrl+C.

The included prebuilt browser application runs without installing its language toolchain. Serve it through the preview; opening the HTML file directly is not supported. The preview binds to 127.0.0.1 and serves only `site/`. Source and native tools remain outside that document root. A port can be selected with `python preview.py --port 4190`.

The browser runs the same Go engine compiled to WebAssembly inside a dedicated worker. Goroutines run concurrently, but this browser target is not a multicore throughput benchmark. A harness cleans up the deliberately blocked example after recording it. The native download includes an HTTP adapter and Go tests.

No account, key, database connection, payment or customer record is needed. The package's simple local navigation is independent of the production site's navigation enhancement. Optional links to the full Zyel catalog and a fresh download point to zyel.io.

## Run and edit native Go

Use Go 1.27; this release was built with Go 1.27.3.

```sh
cd src
go test ./...
go test -run TestOwnership -v ./engine
go run ./cmd/server
```

The server listens only on 127.0.0.1:4188. In a second terminal, POST the included configuration:

```sh
curl -H "Content-Type: application/json" --data-binary @sample-request.json http://127.0.0.1:4188/api/run
```

The native race detector additionally needs a supported C compiler and target:

```sh
go test -race ./...
```

The engine's intentionally broken mode records workers still active when the collector cancels. Its teaching harness then releases them so no demonstration leak is retained. Final active workers should be zero in both modes; peak and cancellation counts explain the difference.

To rebuild the browser engine after editing, return to the package root:

```sh
python rebuild_wasm.py
python refresh_source.py
```

Browser WebAssembly concurrency and native multicore execution are distinct environments. Compare invariants across them, not wall-clock throughput.


## Files and evidence

`FILE_MANIFEST.json` records SHA-256 hashes of the extracted files. `site/lab/go-workers/source/manifest.json` identifies the source displayed in the code viewer. `TEST_MATRIX.md` separates browser, native and optional engine-specific checks. The recording script follows the same reviewed scenarios.

## License and revision labels

Original teaching and application code are MIT-licensed. See THIRD_PARTY_NOTICES.md for the separate runtime licenses and their source. Revision numbers identify editions and do not count earlier public updates. The publication date is separate from the revision label.
