Go Concurrency Patterns
Unverified●30/40Claude Code◐PartialHas SKILL.md but declares no allowed-tools — Claude Code will ask for permission each time
Cursor◐PartialPlain prose you can paste in — but no Cursor rules file
Codex◐PartialPlain prose you can paste in — but no AGENTS.md
Gemini CLI◐PartialPlain prose you can paste in
Copilot◐PartialPlain prose you can paste in — but no Copilot instructions file
npx agentalley add go-concurrency-patternsWho is stuck, and on what
Master Go concurrency with goroutines, channels, sync primitives, and context. Use when building concurrent Go applications, implementing worker pools, or debugging race conditions.
The whole source
Frontmatter — 2 properties
| 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. |
| 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 | ---A5 — No allowed-tools declared — no way to tell what this skill may touch |
| 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 | ```go |
| 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 |
Reviews
Installed this one?Write the first review and take the Trailblazer badge.
Alternatives
Subagent Driven DevelopmentUse when executing implementation plans with independent tasks in the current session◐◐◐◐◐●36/40Python Code Style & DocumentationPython code style, linting, formatting, naming conventions, and documentation standards. Use when writing new code, reviewing style, configuring linters, writing docstrings, or establishing project standards.◐····●35/40Competitor Price Analysis 💲Competitor pricing strategy analysis and market positioning. Price mapping, pricing gaps identification, elasticity signals evaluation, and strategic pricing optimization. Use when the user asks about competitor pricing, price analysis, pricing strategy, or co◐····●34/40Competitor Price Tracker 📊Set up competitor price tracking and monitoring workflows. Track price changes, detect promotions, analyze pricing patterns, and get alerts for competitive price movements.◐····●34/40