Back to list
cemezgin

concurrency

by cemezgin

0🍴 0📅 Jan 17, 2026

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.

RequirementDescription
Context cancellationPass ctx and respect ctx.Done() for graceful shutdown
SynchronizationUse sync.WaitGroup or errgroup.Group to wait for completion
Bounded concurrencyLimit parallel goroutines with semaphore or worker pool
Error propagationUse errgroup when errors need to bubble up
Parallel requestsAlways use errgroup for parallel HTTP/DB/API calls

Pattern Selection

PatternUse When
sync.WaitGroupSimple fan-out, no error collection needed
errgroup.GroupNeed first error, automatic cancellation
errgroup.SetLimit(n)Bounded concurrency with error handling
Worker poolHigh-volume processing, backpressure needed

Do / Don't

DoDon't
errgroup.Group with contextgo func() { process() }()
Worker pool with fixed sizeUnbounded for { go handle() }
select on ctx.Done()Ignore cancellation signals
Explicit wg.Wait()Hope goroutines finish

errgroup for Parallel Requests

Example

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

Example

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

Example

For high-volume processing with backpressure control.

Graceful Shutdown

Example

Always handle context cancellation in long-running goroutines.

Score

Total Score

45/100

Based on repository quality metrics

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

Reviews

💬

Reviews coming soon