Skillshub golang-concurrency
Standards for safe concurrent programming using Goroutines, Channels, and Context. Use when implementing concurrency with Goroutines, Channels, or Context in Go. (triggers: goroutine, go keyword, channel, mutex, waitgroup, context, errgroup, race condition)
install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/HoangNguyen0403/agent-skills-standard/golang-concurrency" ~/.claude/skills/comeonoliver-skillshub-golang-concurrency-268014 && rm -rf "$T"
manifest:
skills/HoangNguyen0403/agent-skills-standard/golang-concurrency/SKILL.mdsource content
Golang Concurrency Standards
Priority: P0 (CRITICAL)
Principles
- Share Memory by Communicating: Don't communicate by sharing memory. Use channels.
- Context is King: Always pass
to efficient manage cancellation/timeouts.ctx - Prevent Leaks: Never start a goroutine without knowing how it will stop.
- Race Detection: Always run tests with
.go test -race
Primitives
- Goroutines: Lightweight threads.
go func() { ... }() - Channels: For data passing + synchronization.
- WaitGroup: Wait for a group of goroutines to finish.
- ErrGroup: WaitGroup + Error propagation (Preferred).
- Mutex: Protect shared state (simpler than channels for just state).
Guidelines
- Buffered vs Unbuffered: Use unbuffered channels for strict synchronization. Use buffered only if you specifically need async decoupling/burst handling.
- Closed Channels: Panic if writing to closed. Reading from closed returns zero-value immediately.
- Select: Use
to handle multiple channels or timeouts.select
References
Anti-Patterns
- No goroutine leaks: Every goroutine needs a known exit path.
- No global state mutation across goroutines: Use channels or sync primitives.
- No bare goroutines without lifecycle: Use errgroup or WaitGroup.