Go Concurrency Patterns
Seth HobsonCommunityCreated by Seth Hobson
- Skill
- Guidelines
- Software development
- MIT
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
This skill provides a structured reference for implementing robust concurrency in Go. It covers essential primitives like goroutines, channels, and synchronization tools, while emphasizing the Go philosophy of communicating by sharing memory. The documentation includes practical implementation patterns such as worker pools, fan-out/fan-in pipelines, and semaphore-based rate limiting, alongside critical best practices for lifecycle management and error handling.
What it does
- Explains core Go concurrency primitives including channels, mutexes, and wait groups.
- Provides implementation patterns for worker pools and concurrent pipelines.
- Demonstrates proper use of context for cancellation and deadline management.
- Outlines best practices to prevent common issues like goroutine leaks and race conditions.
- Offers idiomatic approaches to synchronization and communication between goroutines.
When to use it
- When building concurrent applications that require efficient task processing.
- When implementing worker pools or fan-out/fan-in architectures.
- When you need to manage goroutine lifecycles and graceful shutdowns.
- When debugging race conditions or synchronization issues in Go code.
- When looking for idiomatic ways to handle communication between concurrent processes.
Advantages
- Promotes idiomatic Go concurrency standards.
- Reduces common errors like goroutine leaks and improper channel usage.
- Provides ready-to-use patterns for complex concurrent workflows.
- Focuses on maintainable and safe synchronization techniques.
Usage examples
- “How do I implement a worker pool in Go?”
- The skill provides a WorkerPool pattern using channels and sync.WaitGroup to manage concurrent job processing with context-aware cancellation.
- “What is the best way to merge multiple channels in Go?”
- The skill demonstrates a fan-in pattern using a merge function that utilizes sync.WaitGroup to aggregate results from multiple channels into a single stream.
Install
Download the skill as a ZIP:
https://mp-staging.autogineer.com/agent-skills/wshobson/go-concurrency-patterns/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip go-concurrency-patterns.zip -d .agents/skills
Documentation by Seth Hobson
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
Files
- ATTRIBUTION.mdAdded by AutoGineer1007 B
- LICENSELicence file added by AutoGineer1.0 KiB
- SKILL.md2.7 KiB
- references/details.md10.9 KiB
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- Seth Hobson
- Publisher
- Seth Hobson (Community)
- Source
- wshobson/agents · plugins/systems-programming/skills/go-concurrency-patterns · commit 4bde316
- Licence
- MIT License (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by Seth Hobson.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download go-concurrency-patterns.zip