go-concurrency
БесплатноБез исполняемых скриптовНе проверенUse when writing or reviewing Go concurrency — goroutines, channels, errgroup, context cancellation, or goroutine leaks. Not for sequential idioms…
от Fusengine★ 36 звёзд на GitHubОб этом скилле
Go Concurrency
Goroutines, channels, context, and errgroup for Go 1.27 — plus the number-one
documented pitfall: leaking goroutines on an unbuffered channel + early return.
Agent Workflow (MANDATORY)
Before ANY implementation, spawn 3 agents in parallel, one Agent call each with a name:
- fuse-ai-pilot:explore-codebase - Map existing goroutine/channel/context usage
- fuse-ai-pilot:research-expert - Verify errgroup/context docs via Context7/Exa
- mcp__context7__query-docs - Confirm
golang.org/x/sync/errgroupsignatures
After implementation, run fuse-ai-pilot:sniper for validation, and run tests
with go test -race ./....
Overview
| Feature | Description |
|---|---|
| Goroutines & channels | Lightweight concurrency + typed communication |
| errgroup | Parallelism + error aggregation + context cancellation |
| context | First param, propagated strictly, carries cancellation/deadline |
| WaitGroup vs channels | Counting-only vs result/error passing |
| Race detector | -race in tests/CI to catch data races |
| Leak profile (GA 1.27) | pprof.Lookup("goroutineleak") / /debug/pprof/goroutineleak — no GOEXPERIMENT needed |
Critical Rules
context.Contextis the first parameter - namedctx, never stored in a struct- Every started goroutine must be able to exit - or it leaks (see rule 4)
- Prefer
errgroupfor fan-out with errors - it handles wait + first error + cancel - Unbuffered channel + early return = leak - senders block forever; buffer or drain
- Test with
-race- a passing test without-raceproves nothing about races
Architecture
internal/
├── fetch/
│ ├── fetch.go # errgroup.WithContext fan-out, bounded by SetLimit
│ └── worker.go # worker pool: fixed goroutines drain a jobs channel
└── pipeline/
└── stage.go # ctx-cancellable stages, buffered hand-off channels
→ See errgroup-patterns.md for full example
Reference Guide
Concepts
| Topic | Reference | When to Consult |
|---|---|---|
| Goroutines & channels | goroutines-channels.md | Buffered vs not, select, WaitGroup vs channels |
| errgroup | errgroup.md | Fan-out, error aggregation, SetLimit, TryGo |
| context | context-propagation.md | Cancellation, deadlines, propagation rules |
| Goroutine leaks | goroutine-leaks.md | The #1 pitfall + the goroutineleak profile (GA 1.27) |
Templates
| Template | When to Use |
|---|---|
| errgroup-patterns.md | Bounded parallel work with error handling |
| worker-pool.md | Fixed workers draining a job queue |
Quick Reference
Parallel work with errgroup
g, ctx := errgroup.WithContext(ctx)
g.SetLimit(8) // bound concurrency
for _, u := range urls {
g.Go(func() error { return fetch(ctx, u) })
}
if err := g.Wait(); err != nil { // first non-nil error; cancels ctx
return err
}
→ See errgroup.md
Avoid the leak (buffer so senders never block)
ch := make(chan result, len(items)) // buffered → early return can't strand senders
→ See goroutine-leaks.md
Best Practices
DO
- Pass
ctxfirst and thread it through every blocking call - Reach for
errgroupbefore hand-rollingWaitGroup+ error channels - Buffer result channels to the number of senders, or fully drain them
- Run
go test -race; check thegoroutineleakprofile in CI (GA in 1.27; the 1.26GOEXPERIMENT=goroutineleakprofileflag is deleted)
DON'T
- Return early from a fan-out while goroutines still block on an unbuffered channel
- Store a
context.Contextin a struct field - Use a bare
sync.WaitGroupwhen goroutines return errors (useerrgroup) - Assume tests are race-free without the
-raceflag
Установить go-concurrency в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл go-concurrency?
Use when writing or reviewing Go concurrency — goroutines, channels, errgroup, context cancellation, or goroutine leaks. Not for sequential idioms (go-core-idioms).
Как установить скилл go-concurrency?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл go-concurrency запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic