Go Concurrency taste
# Go Concurrency taste of a backend engineer who wants goroutines that never leak - Start a goroutine only when you know exactly how and when it will stop. Confidence: 0.95 - Pass a context.Context as the first argumen
Works with
claude-code (compatible), claude (compatible), codex (compatible), chatgpt (compatible), gemini-cli (compatible), cursor (compatible), copilot (compatible), opencode (compatible), amp (compatible), roo (compatible), kiro (compatible), goose (compatible), junie (compatible), trae (compatible), cline (compatible), continue (compatible), antigravity (compatible), windsurf (compatible), augment (compatible), qwen-code (compatible), aider (compatible)
Content
Go Concurrency taste of a backend engineer who wants goroutines that never leak
- Start a goroutine only when you know exactly how and when it will stop. Confidence: 0.95
- Pass a
context.Contextas the first argument to every function that blocks or does I/O, and honor its cancellation. Confidence: 0.95 - Use
errgroup.WithContextto run related goroutines together so the first error cancels the rest. Confidence: 0.90 - Prefer plain synchronous APIs and let the caller add concurrency, instead of spawning goroutines inside library code. Confidence: 0.85
- Only the sender closes a channel, and only when no other sender can still write to it. Confidence: 0.90
- Use unbuffered channels by default; add a buffer only with a measured reason and a comment explaining its size. Confidence: 0.75
- Protect shared state with a
sync.Mutexwhen it is simpler than a channel; channels are for passing ownership, not for every lock. Confidence: 0.85 - Keep the mutex right next to the fields it guards and never copy a struct that contains one. Confidence: 0.85
- Bound fan-out with a worker pool or
errgroup.SetLimitinstead of one goroutine per item. Confidence: 0.85 - Every
selectthat waits on work also waits onctx.Done(). Confidence: 0.90 - Use
time.NewTimerorcontext.WithTimeoutinstead oftime.Afterinside loops. Confidence: 0.75 - Use
sync.Onceorsync.OnceValuefor lazy initialization, never a hand-rolled boolean flag. Confidence: 0.80 - Reach for
sync/atomictypes only for simple counters and flags, not for complex invariants. Confidence: 0.75 - Avoid
sync.Mapunless profiling shows lock contention on a read-heavy map. Confidence: 0.70 - Recover panics at goroutine boundaries in long-running servers and turn them into logged errors. Confidence: 0.75
- Run all tests with
-racein CI, and treat any data race report as a release blocker. Confidence: 0.95 - Check for leaked goroutines in tests with
goleak. Confidence: 0.70 - Make shutdown graceful: stop accepting work, drain in-flight jobs, then exit with a deadline. Confidence: 0.90
- Do not use
context.Valuefor optional parameters; it is only for request-scoped data like trace IDs. Confidence: 0.85 - Document in the function comment whether a type is safe for concurrent use. Confidence: 0.80
Source and license
- Source
- Prompts Chat
- Original
- f/awesome-chatgpt-prompts/prompts.csv#go-concurrency-taste
- License
- MIT