z-go-concurrency
Installation
SKILL.md
Go Concurrency
Every goroutine is a liability until proven necessary. Correctness and leak-freedom first.
Principles
- Give every goroutine an exit condition and an owner that waits for completion. A WaitGroup joins work; it does not cancel or unblock it.
- Channel sends copy values, not referenced data. Choose exclusive ownership transfer, immutable sharing, or synchronized mutation.
- Pointer payloads are valid under that protocol. Copied slices, maps, and pointer-bearing structs still share storage; the sender must stop accessing transferred mutable data until ownership returns.
- Assign one closer. Close only after all possible sends finish; with multiple senders, join them before closing.
sync.Onceprevents duplicate closes, not send/close races. - Specify channel direction (
chan<-,<-chan) — compiler prevents misuse. - Default to unbuffered channels; buffers mask backpressure.
- Guard channel operations that must unblock on cancellation with
ctx.Done(). A ready cancellation case has no priority over other ready cases. - Reuse timers when repeated
time.Afterallocations matter; check effective timer semantics before choosing a reset/drain protocol.