一键导入
go-concurrency
Go concurrency patterns with goroutines, channels, errgroup, and sync primitives. Extends core/concurrency with Go-specific implementations.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Go concurrency patterns with goroutines, channels, errgroup, and sync primitives. Extends core/concurrency with Go-specific implementations.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Spec-driven development workflow. Main Claude acts as the lead — spawns critic/scout/architect/builder/tester/reviewer as subagents, enforces human-in-the-loop gates at every phase boundary via AskUserQuestion, records every decision in docs/specs/<slug>/group-log.md. Load this skill whenever the user invokes /define, /orchestrate, /plan, /build, or /ship; whenever a task spans multiple files, packages, or concerns; whenever design decisions need review before implementation; whenever an in-progress spec under docs/specs/<slug>/ needs to resume; or whenever you're about to coordinate critic/scout/architect/builder/tester/reviewer in a sequence. This is the correct skill for any multi-step engineering task that benefits from gated, auditable execution — do not try to coordinate specialists ad-hoc.
Artifact contract for docs/specs/<slug>/ — spec.md template, frontmatter schema (task/status/current_group/total_groups/created/updated), spec directory layout, contracts-trigger rules, and parallelization markers ([P]). Load this skill whenever you're creating a new docs/specs/<slug>/ directory, authoring or editing spec.md, checking whether an existing spec matches the template (e.g., during review, resumption, or session-start scan), validating frontmatter values, or deciding whether a task needs contracts.md. Pair with core/orchestration, which owns the workflow that populates these artifacts.
Author and maintain a project constitution at docs/constitution.md — the list of invariants that reviewer and critic enforce on every spec and every diff. Load this skill whenever you're creating a new constitution from scratch or from EXAMPLE_CONSTITUTION.md, proposing candidate invariants via /constitution-propose, adding or editing an invariant, sunsetting an obsolete rule, or promoting a recurring "don't do X" review comment into an enforced invariant. Also use when a post-incident review surfaces a rule that should have been caught mechanically. Reviewer and critic consume the registered invariants automatically via the project_constitution session-start field — you do not need this skill for enforcement, only for authoring.
Ground a task in the existing codebase before specification — grep for prior art, read similar features, surface inherited gotchas, write discovery.md. Load this skill whenever you're running scout during /define or /orchestrate, whenever a task touches an area of the codebase you have not read in this session, whenever the task mentions a feature name that might already exist, or whenever recent_learnings flags a gotcha or pattern near the task. Prevents specs built on phantom assumptions.
Decision tree for routing any task to the right agent and skill set. Loaded on session start and consulted whenever you're unsure which specialist applies, which skill combination to load for a given task, or when main Claude (running core/orchestration) needs to decide which subagent to spawn for a Phase 3 subtask. Also surfaces available CLI tools, MCP servers, and user-installed skills/agents/plugins so you can prefer what's actually on the machine.
Output compression for human-facing responses. Use when responding to users in a terminal, writing end-of-turn summaries, explaining diffs, producing status updates, or any non-artifact output addressed to a human reader. Specifies what to compress (articles, filler, pleasantries, hedging) and what to leave full-fidelity (SPEC files, agent-to-agent reports, commands, code blocks, paths, acceptance criteria, inline docstrings). Triggered automatically by the /compact slash command and loaded by all agents by default.
| name | go/concurrency |
| description | Go concurrency patterns with goroutines, channels, errgroup, and sync primitives. Extends core/concurrency with Go-specific implementations. |
Channels orchestrate; mutexes serialize. Use errgroup for managed goroutine coordination.
| Channels | Mutexes |
|---|---|
| Passing ownership of data | Protecting internal state |
| Coordinating goroutines | Simple counter or flag |
| Distributing work | Short critical sections |
func (s *Server) Start(ctx context.Context) error {
g, ctx := errgroup.WithContext(ctx)
g.Go(func() error { return s.httpServer.Serve(ctx) })
g.Go(func() error { return s.processQueue(ctx) })
return g.Wait()
}
Every go statement needs a way to stop and wait. Use errgroup.Group for error propagation, sync.WaitGroup when errors not needed.
func ProcessItems(ctx context.Context, items []Item, workers int) error {
g, ctx := errgroup.WithContext(ctx)
g.SetLimit(workers) // Go 1.20+: simpler bounded concurrency
for _, item := range items {
g.Go(func() error { return process(ctx, item) })
}
return g.Wait()
}
Use SetLimit for simple fan-out. Use full channel-based pool for streaming input.
func FetchAll(ctx context.Context, urls []string) ([]Result, error) {
results := make([]Result, len(urls))
g, ctx := errgroup.WithContext(ctx)
for i, url := range urls {
g.Go(func() error {
res, err := fetch(ctx, url)
if err != nil { return fmt.Errorf("fetching %s: %w", url, err) }
results[i] = res // Safe: unique index per goroutine
return nil
})
}
if err := g.Wait(); err != nil { return nil, err }
return results, nil
}
// Pipeline reads from input, transforms each value, and writes to out.
// The SENDER of `input` owns closing it; when input closes, the range
// loop exits and this stage closes `out` via the deferred close.
// Context cancellation exits immediately without draining input.
func Pipeline(ctx context.Context, input <-chan int) <-chan int {
out := make(chan int)
go func() {
defer close(out)
for n := range input {
select {
case out <- transform(n):
case <-ctx.Done(): return
}
}
}()
return out
}
Pipeline stages chain by passing the output channel of one stage as the input of the next. Each stage is responsible for closing its own output; each stage expects its input to be closed by its sender. This is the key invariant — violating it causes goroutine leaks (blocked on send) or panics (send on closed channel).
import "golang.org/x/time/rate"
limiter := rate.NewLimiter(rate.Limit(rps), burst)
if err := limiter.Wait(ctx); err != nil { return err } // blocking
if !limiter.Allow() { return errors.New("rate limited") } // non-blocking
// Lazy init
c.initOnce.Do(func() { c.conn, c.initErr = grpc.Dial(c.addr) })
// Deduplicate concurrent calls
v, err, _ := c.group.Do(key, func() (any, error) { return c.db.Query(ctx, key) })
// Reuse temporary objects (profile first)
buf := bufPool.Get().(*bytes.Buffer)
defer func() { buf.Reset(); bufPool.Put(buf) }()
// BAD: goroutine leak
go func() { for { process(); time.Sleep(time.Second) } }()
// GOOD: respect cancellation
go func() {
ticker := time.NewTicker(time.Second); defer ticker.Stop()
for { select { case <-ticker.C: process(); case <-ctx.Done(): return } }
}()
// BAD: race condition
var count int; go func() { count++ }()
// GOOD: use atomic
var count atomic.Int64; go func() { count.Add(1) }()
// BAD: unbounded goroutines
for _, item := range items { go process(item) }
// GOOD: use errgroup.SetLimit or worker pool
go vet ./... reports no issuesgo test -race ./... passes with no data races detectederrgroup used for goroutine coordination with error propagationsync.Mutex instead)