← スキル一覧に戻る

concurrency
by cemezgin
⭐ 0🍴 0📅 2026年1月17日
SKILL.md
name: concurrency description: Goroutine ownership, errgroup patterns, worker pools, and graceful shutdown. Use when writing concurrent code or parallel request handling. userInvokable: true
Concurrency
References: Examples
Core Rule
No fire-and-forget goroutines. Every goroutine must have managed lifecycle.
| Requirement | Description |
|---|---|
| Context cancellation | Pass ctx and respect ctx.Done() for graceful shutdown |
| Synchronization | Use sync.WaitGroup or errgroup.Group to wait for completion |
| Bounded concurrency | Limit parallel goroutines with semaphore or worker pool |
| Error propagation | Use errgroup when errors need to bubble up |
| Parallel requests | Always use errgroup for parallel HTTP/DB/API calls |
Pattern Selection
| Pattern | Use When |
|---|---|
sync.WaitGroup | Simple fan-out, no error collection needed |
errgroup.Group | Need first error, automatic cancellation |
errgroup.SetLimit(n) | Bounded concurrency with error handling |
| Worker pool | High-volume processing, backpressure needed |
Do / Don't
| Do | Don't |
|---|---|
errgroup.Group with context | go func() { process() }() |
| Worker pool with fixed size | Unbounded for { go handle() } |
select on ctx.Done() | Ignore cancellation signals |
Explicit wg.Wait() | Hope goroutines finish |
errgroup for Parallel Requests
g, ctx := errgroup.WithContext(ctx)
g.Go(func() error { return fetchA(ctx) })
g.Go(func() error { return fetchB(ctx) })
g.Go(func() error { return fetchC(ctx) })
if err := g.Wait(); err != nil {
return fmt.Errorf("parallel fetch: %w", err)
}
Bounded Concurrency
g, ctx := errgroup.WithContext(ctx)
g.SetLimit(10) // Max 10 concurrent goroutines
for _, item := range items {
item := item
g.Go(func() error { return process(ctx, item) })
}
return g.Wait()
Worker Pool
For high-volume processing with backpressure control.
Graceful Shutdown
Always handle context cancellation in long-running goroutines.
スコア
総合スコア
45/100
リポジトリの品質指標に基づく評価
✓SKILL.md
SKILL.mdファイルが含まれている
+20
○LICENSE
ライセンスが設定されている
0/10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
○言語
プログラミング言語が設定されている
0/5
○タグ
1つ以上のタグが設定されている
0/5
レビュー
💬
レビュー機能は近日公開予定です