golang-concurrency

Guides writing and reviewing concurrent Go code using goroutines, channels, and sync primitives.

1|Updated Feb 2, 2026
One-click install
npx skills add https://github.com/rockcookies/skills --skill golang-concurrency-rockcookies
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-concurrency
Source: https://github.com/rockcookies/skills/tree/main/skills/samber-golang/golang-concurrency
Command: npx skills add https://github.com/rockcookies/skills --skill golang-concurrency-rockcookies

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Concurrent Go code is prone to goroutine leaks, race conditions, deadlocks, and channel misuse that crash production systems. This Skill provides structured guidance for writing, reviewing, and auditing concurrent Go code so every goroutine has a clear owner, exit path, and error propagation. ## Core Features & Use Cases - Concurrency Patterns: Decision tables for choosing between channels, mutexes, atomics, sync.Map, WaitGroup, errgroup, and singleflight based on your scenario. - Three Operating Modes: Write mode for implementing concurrent code, review mode for PR diffs, and audit mode that fans out up to 5 parallel sub-agents to scan a codebase for leaks and unsafe shared state. - Deep Reference Guides: Detailed patterns for channels/select, pipelines and worker pools, and sync primitives including Go 1.23+ iterators and Go 1.25 WaitGroup.Go. - Use Case: When reviewing a PR that spawns goroutines in a loop, the Skill flags missing ctx.Done() in select statements, wg.Add placement races, and unbounded spawning, then suggests errgroup.SetLimit as the fix. ## Quick Start Ask the AI to review your Go file for goroutine leaks and race conditions using the golang-concurrency skill.

Frequently Asked Questions about golang-concurrency

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent goroutine leaks in Go?▼

Give every goroutine a clear exit path using context cancellation or a done channel, and always include ctx.Done() in select statements. Use sync.WaitGroup or errgroup to wait for completion, and add go.uber.org/goleak in TestMain to detect leaks in tests.

When should I use errgroup instead of WaitGroup in Go?▼

Use errgroup when you need error propagation, cancellation of sibling goroutines on first error via errgroup.WithContext, or bounded concurrency via SetLimit. Use WaitGroup only for simple fire-and-wait goroutines that return no errors.

Should I use channels or mutexes for shared state in Go?▼

Use channels when passing data between goroutines since they transfer ownership explicitly. Use sync.Mutex or sync.RWMutex to protect shared struct fields, and sync/atomic for simple counters and flags.

When is sync.Map the wrong choice in Go?▼

sync.Map is optimized for write-once/read-many patterns or disjoint key sets. For frequent writes with overlapping keys, a plain map guarded by sync.RWMutex is faster, and unsynchronized concurrent map access causes a hard crash.

Why does time.After in a select loop cause problems?▼

Each time.After call allocates a new timer, creating churn in hot loops. Create a time.NewTimer outside the loop and call Reset after each event; on Go versions before 1.23, drain the channel if Stop reports a pending value.

Who should close a channel in Go, sender or receiver?▼

Only the sender closes a channel; closing from the receiver panics if the sender writes after close. Receivers signal completion through a separate done channel or context cancellation instead.