Master Go concurrency with goroutines, channels

Go concurrency patterns

by wshobson · MIT license · ★ 39,857 on GitHub · updated Sep 21

Go concurrency patterns cover

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 Codenpx skills add wshobson/agents --skill go-concurrency-patterns -g -a claude-code
Claude 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-patterns
Windows (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" -Force
Claude.ai / desktopDownload the ZIP and upload it under Settings → Capabilities → Skills.
Codex, Cursor, other agentsPoint them at SKILL.md. The other files are plain text.

Connects with Agent Alley MCP · agentalley.io/mcp

Files included

  • SKILL.md2.7 KB
  • references/1 file · 10.7 KB
Read the files here
wshobson/4236bb92 files
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---
2name: go-concurrency-patterns
3description: 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 
8Production 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```
35Don't communicate by sharing memory;
36share memory by communicating.
37```
38 
39## Quick Start
40 
41```go
42package main
43 
44import (
45 "context"
46 "fmt"
47 "sync"
48 "time"
49)
50 
51func 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 
76func 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 
89Detailed 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 
View all files on GitHub →

Details

Updated
Sep 21, 2026
License
MIT
Stars on the repo
★ 39,857
Checked
Source
wshobson/agents ↗
Creator
wshobson · 179 listings
View creator

Similar skills

See all →
SkillA task is too large for one model passAdvisor orchestrator workerShubhamsaboo/awesome-llm-apps · by ShubhamsabooUse when a task is too large for one model pass, needs parallel research or generation across many subtasks (like researching a dozen competitors at once), or the user asks to orchestrate multiple models, split work across a model team, run an advisor-worker loop, have a stronger model review the plan while cheap workers execute, or says "too big for one model" or "fan this out". Not for single-file edits or tasks one model handles in one pass.★ 139k GitHub starsSkillRun the CCS Align seat's hourly breathing cycleCCS Align — Worker Watch seat (Phases 0–2 shipped; Phase 3 = verify / sign-off)thedotmack/claude-mem · by thedotmackRun the CCS Align seat's hourly breathing cycle — prove the local claude-mem worker is healthy, pull needle observations through search → timeline → get_observations, land them in a seat-owned middle cache via atomic grab → append → filter exclude-marks → replace, manage exclude marks, and walk house → project → seat rules to detect conflicts (SHADOW_HOUSE, DENY_ALLOW, DRIFT, CLOCK_HEADER) with an append-only rules-report.md. Use when asked to run CCS Align, breathe the alignment seat, refresh the middle cache, exclude or restore an observation, walk rules, check rules conflicts, or check the Worker Watch board.★ 95.6k GitHub starsSkillSummarize and review what changed while you were awayCatchup — Async-Team Return Briefingoliver-kriska/claude-elixir-phoenix · by oliver-kriskaSummarize and review what changed while you were away. Use after a weekend, vacation, or flight to check missed PRs, git commits, Linear tickets, and meetings — one prioritized brief, not a firehose.★ 560 GitHub starsSkillMaster Python asyncio, concurrent programmingAsync python patternswshobson/agents · by wshobsonMaster Python asyncio, concurrent programming, and async/await patterns for high-performance applications. Use when building async APIs, concurrent systems, or I/O-bound applications requiring non-blocking operations.★ 39.9k GitHub starsSkillDesign microservices architectures with service boundariesMicroservices patternswshobson/agents · by wshobsonDesign microservices architectures with service boundaries, event-driven communication, and resilience patterns. Use when building distributed systems, decomposing monoliths, or implementing microservices.★ 39.9k GitHub starsSkillMaster ES6+ features including async/await, destructuringModern javascript patternswshobson/agents · by wshobsonMaster ES6+ features including async/await, destructuring, spread operators, arrow functions, promises, modules, iterators, generators, and functional programming patterns for writing clean, efficient JavaScript code. Use when refactoring legacy code, implementing modern patterns, or optimizing JavaScript applications.★ 39.9k GitHub stars

More from wshobson

SkillMaster C/.NET backend development patterns for buildingwshobson/agents · by wshobsonMaster C#/.NET backend development patterns for building robust APIs, MCP servers, and enterprise applications. Covers async/await, dependency injection, Entity Framework Core, Dapper, configuration, caching, and testing with xUnit. Use when developing .NET backends, reviewing C# code, or designing API architectures.★ 39.9k GitHub starsSkillImplement WCAG 2.2 compliant interfaces with mobileAccessibility compliancewshobson/agents · by wshobsonImplement WCAG 2.2 compliant interfaces with mobile accessibility, inclusive design patterns, and assistive technology support. Use when auditing accessibility, implementing ARIA patterns, building for screen readers, or ensuring inclusive user experiences.★ 39.9k GitHub starsSkillMaster Material Design 3 and Jetpack Compose patternsAndroid Mobile Designwshobson/agents · by wshobsonMaster Material Design 3 and Jetpack Compose patterns for building native Android apps. Use when designing Android interfaces, implementing Compose UI, or following Google's Material Design guidelines.★ 39.9k GitHub starsSkillMigrate from AngularJS to Angular using hybrid modeAngular migrationwshobson/agents · by wshobsonMigrate from AngularJS to Angular using hybrid mode, incremental component rewriting, and dependency injection updates. Use when upgrading AngularJS applications, planning framework migrations, or modernizing legacy Angular code.★ 39.9k GitHub starsSkillUnderstand anti-reversing, obfuscationAnti reversing techniqueswshobson/agents · by wshobsonUnderstand anti-reversing, obfuscation, and protection techniques encountered during software analysis. Use this skill when analyzing malware evasion techniques, when implementing anti-debugging protections for CTF challenges, when reverse engineering packed binaries, or when building security research tools that need to detect virtualized environments.★ 39.9k GitHub starsSkillBuild production Apache Airflow DAGs with best practicesApache Airflow DAG Patternswshobson/agents · by wshobsonBuild production Apache Airflow DAGs with best practices for operators, sensors, testing, and deployment. Use when creating data pipelines, orchestrating workflows, or scheduling batch jobs.★ 39.9k GitHub stars