Module 3 · Exercise 2 · ~40 min · Real Go code

Context-Aware Worker Pool

Build a bounded-concurrency worker pool with proper context handling and first-error-wins propagation. The same shape as errgroup.Group in the wild — and the shape you'll use for parallel command submission, parallel queries, parallel anything.

Where
cd module-03-concurrency/exercises/exercise-02-worker-pool
go test -v -race ./...

The signature

err := workerpool.Run(ctx, workers, tasks)

That's the whole API. Underneath, the pool must:

Tactical hints

Why this is THE pattern

Real Canton-adjacent code does this everywhere — submitting a batch of commands in parallel, fetching state for many parties concurrently, processing a transaction-stream window. Once you've written this once, the production version (with metrics, with retries) is a small extension of the same shape.

The standard library's golang.org/x/sync/errgroup is essentially this — go read its source after passing tests.