Go Concurrency Pattern Guide
Go concurrency patterns

Master Go concurrency with goroutines, channels, sync primitives, and context. Use when building concurrent Go applications, implementing worker pools, or debugging race conditions.
--- name: go-concurrency-patterns description: Master Go concurrency with goroutines, channels, sync primitives, and context. Use when building concurrent Go applications, implementing worker pools, or debugging race conditions. --- # Go Concurrency Patterns Production patterns for Go concurrency including goroutines, channels, synchronization primitives, and context management. ## When to Use This Skill - Building concurrent Go applications - Implementing worker pools and pipelines - Managing goroutine lifecycles - Using channels for communication - Debugging race conditions - Implementing graceful shutdown
Overview
Production patterns for Go concurrency including goroutines, channels, synchronization primitives, and context management.
Manual install (npx, ZIP)
Claude Code
npx skills add wshobson/agents --skill go-concurrency-patterns -g -a claude-codeClaude Code (manual)
mkdir -p ~/.claude/skills && curl -sL https://codeload.github.com/wshobson/agents/tar.gz/4236bb91f839 \
| tar -xz -C ~/.claude/skills --strip-components=4 agents-4236bb91f839/plugins/systems-programming/skills/go-concurrency-patternsWindows (PowerShell)
New-Item -ItemType Directory -Force "$HOME\.claude\skills" | Out-Null; Invoke-WebRequest "https://m.agentalley.io/zip/1876b76c1399c6db73ec/go-concurrency-patterns.zip" -OutFile "$env:TEMP\go-concurrency-patterns.zip"; Expand-Archive "$env:TEMP\go-concurrency-patterns.zip" -DestinationPath "$HOME\.claude\skills" -ForceClaude.ai / desktop
Codex, Cursor, other agents
Connects with Agent Alley MCP · agentalley.io/mcp
Files included
SKILL.md2.7 KBreferences/1 file · 10.7 KB
Read the files here
SKILL.md
Show the full text108 lines
Go Concurrency Patterns
Production patterns for Go concurrency including goroutines, channels, synchronization primitives, and context management.
When to Use This Skill
- Building concurrent Go applications
- Implementing worker pools and pipelines
- Managing goroutine lifecycles
- Using channels for communication
- Debugging race conditions
- Implementing graceful shutdown
Core Concepts
1. Go Concurrency Primitives
| Primitive | Purpose |
|---|---|
goroutine |
Lightweight concurrent execution |
channel |
Communication between goroutines |
select |
Multiplex channel operations |
sync.Mutex |
Mutual exclusion |
sync.WaitGroup |
Wait for goroutines to complete |
context.Context |
Cancellation and deadlines |
2. Go Concurrency Mantra
Don't communicate by sharing memory;
share memory by communicating.
Quick Start
package main
import (
"context"
"fmt"
"sync"
"time"
)
func main() {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
results := make(chan string, 10)
var wg sync.WaitGroup
// Spawn workers
for i := 0; i < 3; i++ {
wg.Add(1)
go worker(ctx, i, results, &wg)
}
// Close results when done
go func() {
wg.Wait()
close(results)
}()
// Collect results
for result := range results {
fmt.Println(result)
}
}
func worker(ctx context.Context, id int, results chan<- string, wg *sync.WaitGroup) {
defer wg.Done()
select {
case <-ctx.Done():
return
case results <- fmt.Sprintf("Worker %d done", id):
}
}
Detailed patterns and worked examples
Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.
Best Practices
Do's
- Use context - For cancellation and deadlines
- Close channels - From sender side only
- Use errgroup - For concurrent operations with errors
- Buffer channels - When you know the count
- Prefer channels - Over mutexes when possible
Don'ts
- Don't leak goroutines - Always have exit path
- Don't close from receiver - Causes panic
- Don't use shared memory - Unless necessary
- Don't ignore context cancellation - Check ctx.Done()
- Don't use time.Sleep for sync - Use proper primitives
| 1 | |
| 2 | name go-concurrency-patterns |
| 3 | description Master Go concurrency with goroutines, channels, sync primitives, and context. Use when building concurrent Go applications, implementing worker pools, or debugging race conditions. |
| 4 | |
| 5 | |
| 6 | # Go Concurrency Patterns |
| 7 | |
| 8 | Production patterns for Go concurrency including goroutines, channels, synchronization primitives, and context management. |
| 9 | |
| 10 | ## When to Use This Skill |
| 11 | |
| 12 | Building concurrent Go applications |
| 13 | Implementing worker pools and pipelines |
| 14 | Managing goroutine lifecycles |
| 15 | Using channels for communication |
| 16 | Debugging race conditions |
| 17 | Implementing graceful shutdown |
| 18 | |
| 19 | ## Core Concepts |
| 20 | |
| 21 | ### 1. Go Concurrency Primitives |
| 22 | |
| 23 | | Primitive | Purpose | |
| 24 | | ----------------- | -------------------------------- | |
| 25 | | `goroutine` | Lightweight concurrent execution | |
| 26 | | `channel` | Communication between goroutines | |
| 27 | | `select` | Multiplex channel operations | |
| 28 | | `sync.Mutex` | Mutual exclusion | |
| 29 | | `sync.WaitGroup` | Wait for goroutines to complete | |
| 30 | | `context.Context` | Cancellation and deadlines | |
| 31 | |
| 32 | ### 2. Go Concurrency Mantra |
| 33 | |
| 34 | |
| 35 | Don't communicate by sharing memory; |
| 36 | share memory by communicating. |
| 37 | |
| 38 | |
| 39 | ## Quick Start |
| 40 | |
| 41 | |
| 42 | package main |
| 43 | |
| 44 | import ( |
| 45 | "context" |
| 46 | "fmt" |
| 47 | "sync" |
| 48 | "time" |
| 49 | ) |
| 50 | |
| 51 | func main() { |
| 52 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 53 | defer cancel() |
| 54 | |
| 55 | results := make(chan string, 10) |
| 56 | var wg sync.WaitGroup |
| 57 | |
| 58 | // Spawn workers |
| 59 | for i := 0; i < 3; i++ { |
| 60 | wg.Add(1) |
| 61 | go worker(ctx, i, results, &wg) |
| 62 | } |
| 63 | |
| 64 | // Close results when done |
| 65 | go func() { |
| 66 | wg.Wait() |
| 67 | close(results) |
| 68 | }() |
| 69 | |
| 70 | // Collect results |
| 71 | for result := range results { |
| 72 | fmt.Println(result) |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | func worker(ctx context.Context, id int, results chan<- string, wg *sync.WaitGroup) { |
| 77 | defer wg.Done() |
| 78 | |
| 79 | select { |
| 80 | case <-ctx.Done(): |
| 81 | return |
| 82 | case results <- fmt.Sprintf("Worker %d done", id): |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | |
| 87 | ## Detailed patterns and worked examples |
| 88 | |
| 89 | Detailed pattern documentation lives in `references/details.md`. Read that file when the navigation tier above is insufficient. |
| 90 | |
| 91 | ## Best Practices |
| 92 | |
| 93 | ### Do's |
| 94 | |
| 95 | **Use context** - For cancellation and deadlines |
| 96 | **Close channels** - From sender side only |
| 97 | **Use errgroup** - For concurrent operations with errors |
| 98 | **Buffer channels** - When you know the count |
| 99 | **Prefer channels** - Over mutexes when possible |
| 100 | |
| 101 | ### Don'ts |
| 102 | |
| 103 | **Don't leak goroutines** - Always have exit path |
| 104 | **Don't close from receiver** - Causes panic |
| 105 | **Don't use shared memory** - Unless necessary |
| 106 | **Don't ignore context cancellation** - Check ctx.Done() |
| 107 | **Don't use time.Sleep for sync** - Use proper primitives |
| 108 |
Details
- Updated
- Sep 21, 2026
- License
- MIT
- Stars on the repo
- ★ 39,857
- Checked
- Source
- wshobson/agents ↗
- Creator
- wshobson · 179 listings
Similar skills
See all →
SkillAdvisor Orchestrator
SkillCCS Align Worker Watch
SkillAsync Return Briefing
SkillAsync Python Patterns
SkillMicroservices Patterns
SkillES6+ JavaScript PatternsMore from wshobson
Skill.NET Backend Developer
SkillWCAG 2.2 Implementation
SkillMaterial Design 3 & Compose
SkillAngularJS to Angular Upgrade
SkillReverse Engineering Defense
SkillApache Airflow DAG Builder