golang-concurrency

Implements and reviews concurrent Go code using goroutines, channels, and sync primitives.

Updated Jun 15, 2026
One-click install
npx skills add https://github.com/2877389577/novels_ai_gen --skill golang-concurrency-2877389577
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-concurrency
Source: https://github.com/2877389577/novels_ai_gen/tree/main/.agents/skills/golang-concurrency
Command: npx skills add https://github.com/2877389577/novels_ai_gen --skill golang-concurrency-2877389577

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing correct concurrent Go code is error-prone: goroutine leaks, race conditions, channel ownership violations, and deadlocks are common and hard to detect. This Skill provides structured guidance for writing, reviewing, and auditing concurrent Go code so every goroutine has a clear exit, channels have defined ownership, and shared state is properly synchronized. ## Core Features & Use Cases - Write mode: Implement goroutines, channels, select loops, worker pools, and fan-out/fan-in pipelines following structured concurrency rules (context cancellation, sender-closes-channel, unbuffered-by-default). - Review mode: Check PR diffs for goroutine leaks, missing ctx.Done() in select, WaitGroup Add/Done ordering bugs, and unprotected shared state. - Audit mode: Run up to 5 parallel sub-agents to audit an entire codebase for concurrency anti-patterns. - Decision tables: Choose between channels vs mutexes vs atomics, WaitGroup vs errgroup, sync.Map vs RWMutex+map, and iterators vs goroutine pipelines. - Use Case: You need to fetch 50 URLs concurrently with at most 10 in flight and cancel everything on the first error — the Skill guides you to errgroup.WithContext with SetLimit(10) instead of a hand-rolled worker pool. ## Quick Start Ask the agent to review your Go code for goroutine leaks and race conditions, or to write a bounded worker pool using errgroup.

Frequently Asked Questions about golang-concurrency

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent goroutine leaks in Go?▼

Every goroutine needs a clear exit path: pass a context.Context and include a ctx.Done() case in every select loop, or use a done channel. Verify with go.uber.org/goleak in TestMain and run tests with go test -race to catch leaks and data races.

When should I use errgroup instead of sync.WaitGroup?▼

Use errgroup when goroutines return errors, need cancellation of siblings on first failure, or need bounded concurrency via SetLimit. Use WaitGroup only for simple fire-and-wait work with no error propagation; Go 1.25+ offers wg.Go for that case.

Should I use sync.Map or RWMutex with a plain map?▼

Use sync.Map only for write-once/read-many patterns or disjoint key sets per goroutine. For frequent writes with overlapping keys, RWMutex plus a plain map is faster. Unsynchronized concurrent map access causes a hard crash, not just a race.

Who should close a channel in Go, sender or receiver?▼

Only the sender closes a channel; closing from the receiver panics if the sender writes afterward. If the receiver needs to stop the producer, use a separate done channel or context cancellation that the producer selects on.

Why is time.After inside a for-select loop a problem?▼

Each time.After call allocates a new timer, causing churn in hot loops. Create one time.NewTimer outside the loop and call Reset after each event; on Go versions before 1.23, drain the channel if Stop reports a pending value.

When should I use Go 1.23 iterators instead of a channel pipeline?▼

Use iter.Seq iterators for sequential, CPU-bound, in-memory transformations where goroutines add overhead without benefit. Reserve goroutine-plus-channel pipelines for stages involving I/O or when you need true parallelism across cores.