go-concurrency

Implements and reviews Go concurrency patterns using goroutines, channels, errgroup, and context cancellation.

1|Updated Jul 29, 2026
One-click install
npx skills add https://github.com/fusengine/kimi-code --skill go-concurrency-fusengine
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: go-concurrency
Source: https://github.com/fusengine/kimi-code/tree/main/plugins/go-expert/skills/go-concurrency
Command: npx skills add https://github.com/fusengine/kimi-code --skill go-concurrency-fusengine

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires golang.org/x/sync, and includes references (resource) components.

What problem does it solve? Writing concurrent Go code without leaks or data races is error-prone: unbuffered channels combined with early returns strand goroutines forever, raw WaitGroups cannot propagate errors, and tests without the race detector prove nothing. This Skill provides verified patterns and review rules for goroutines, channels, errgroup, and context propagation in Go 1.26. ## Core Features & Use Cases - errgroup fan-out patterns: Bounded parallel work with SetLimit, first-error propagation, and automatic context cancellation via errgroup.WithContext. - Leak prevention and diagnosis: Fixes the documented unbuffered-channel-plus-early-return pitfall and covers the Go 1.26 goroutineleak pprof profile for detecting stranded goroutines. - Context propagation rules: Enforces ctx as the first parameter, strict cancellation handling, and correct use of WithTimeout and WithValue. - Use Case: When implementing a service that fetches hundreds of URLs in parallel, apply the errgroup template with SetLimit and per-index result slots to get bounded, cancellable, leak-free concurrency, then validate with go test -race. ## Quick Start Ask the agent to implement a bounded parallel fetch over a list of URLs using errgroup with context cancellation and then run the tests with the race detector enabled.

Frequently Asked Questions about go-concurrency

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

FAQPage Schema
How do I run goroutines in parallel and collect errors in Go?▼

Use errgroup.WithContext to spawn goroutines with g.Go, then call g.Wait to get the first non-nil error. The first failure cancels the group context so sibling goroutines stop, and SetLimit bounds how many run at once.

When should I use errgroup vs sync.WaitGroup in Go?▼

Use sync.WaitGroup only when goroutines produce no results or errors and you just need to wait for completion. Use errgroup whenever goroutines return errors, since it aggregates the first error and cancels the others automatically.

Why do goroutines leak with unbuffered channels in Go?▼

A goroutine sending on an unbuffered channel blocks until a receiver reads, so an early return in the collector strands remaining senders forever. Fix it by buffering the channel to the number of senders or by using errgroup with context cancellation.

How do I detect goroutine leaks in Go 1.26?▼

Go 1.26 adds an experimental goroutineleak profile enabled with GOEXPERIMENT=goroutineleakprofile at build time. It is available via runtime/pprof as goroutineleak and at /debug/pprof/goroutineleak, reporting goroutines blocked on primitives that can never unblock.

Should context.Context be stored in a struct in Go?▼

No, context.Context should be passed as the first function parameter named ctx and propagated down the call chain. Storing it in a struct lets it outlive its request and defeats cancellation; always derive and defer cancel for WithTimeout or WithCancel.