Go Concurrency Rules

Go Concurrency Rules

Sets a list of Go concurrency preferences, covering goroutine lifetimes, context cancellation, channels, mutexes and errgroup, for an AI to follow when writing or reviewing Go code.

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 argument to every function that blocks or does I/O, and honor its cancellation. Confidence: 0.95
  • Use errgroup.WithContext to 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.Mutex when 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.SetLimit instead of one goroutine per item. Confidence: 0.85
  • Every select that waits on work also waits on ctx.Done(). Confidence: 0.90
  • Use time.NewTimer or context.WithTimeout instead of time.After inside loops. Confidence: 0.75
  • Use sync.Once or sync.OnceValue for lazy initialization, never a hand-rolled boolean flag. Confidence: 0.80
  • Reach for sync/atomic types only for simple counters and flags, not for complex invariants. Confidence: 0.75
  • Avoid sync.Map unless 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 -race in 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.Value for 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

Public domain (CC0 1.0) · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 6,373 prompts

More by @OpenSourceBuffGuy

See all
Website Clone Architect prompt image

Website Clone Architect

Reverse-engineers a website section by section, writes component specs, and hands them to parallel builder agents in git worktrees to rebuild it.

agent-skill, orchestrator, parallel-agents, multi-agent, plan-then-execute, web-development, frontend, codebase-analysis, scaffolding, css, html, nextjs, typescript, git, mcp, claude-code, for-developers, for-designers, long-form, advanced, technical-spec, task-decomposition, structured-output, design-systems, ui-ux, tool-use, checklist, report, vibe-coding

Italian Terrace Cafe Candid Portrait prompt image

Italian Terrace Cafe Candid Portrait

Generates a photorealistic candid shot of a woman in a white corset dress laughing at a sunny hotel terrace cafe, written as detailed JSON.

image-prompt, json-prompt, structured-output, photorealistic, portrait, woman, candid, fashion, cottagecore, natural-light, golden-hour, bokeh, summer, travel, cityscape, mountains, medium-shot, vibrant-colors, for-photographers, nano-banana, fashion-shoot, luxury

Night Street Photo With Leashed Cat prompt image

Night Street Photo With Leashed Cat

Generates a flash-lit night street photo of a blonde woman in a retro track jacket walking a hissing tabby cat on a leash.

image-prompt, json-prompt, nano-banana, structured-output, portrait, woman, animals, pet-portrait, night-scene, street-photography, candid, editorial, fashion, dramatic-lighting, photorealistic, vertical-format, medium-shot, graffiti, for-photographers, for-content-creators

1 view

Reviews

Loading reviews…

Discussion

Loading comments…