# Go Concurrency Patterns

> Use when implementing Go concurrency patterns.

- Skill: `loopyluci/go-concurrency-patterns` (Agent Skill)
- Install (CLI): `npx skillmds@latest add loopyluci/go-concurrency-patterns`
- Raw SKILL.md: https://api.skillmd.com/api/skills/loopyluci/go-concurrency-patterns/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- License: MIT
- Author: LoopyLuci (https://skillmd.com/u/loopyluci)
- Updated: 2026-09-08
- Page: https://skillmd.com/skills/loopyluci/go-concurrency-patterns

---


# Go Concurrency Patterns

Implementing Go concurrency patterns — from goroutines and channels through pipelines, fan-out/in, and advanced sync primitives.

## When to Use

- Building concurrent Go applications
- Implementing worker pools and pipelines
- Managing goroutine lifecycles
- Synchronization with channels and mutexes

## Concurrency Patterns

```go
// Pipeline pattern
func gen(nums ...int) <-chan int {
    out := make(chan int)
    go func() { for _, n := range nums { out <- n }; close(out) }()
    return out
}

func sq(in <-chan int) <-chan int {
    out := make(chan int)
    go func() { for n := range in { out <- n * n }; close(out) }()
    return out
}

// Fan-out / Fan-in
func merge(cs ...<-chan int) <-chan int {
    var wg sync.WaitGroup
    out := make(chan int)
    output := func(c <-chan int) {
        for n := range c { out <- n }
        wg.Done()
    }
    wg.Add(len(cs))
    for _, c := range cs { go output(c) }
    go func() { wg.Wait(); close(out) }()
    return out
}
```

## Verification Checklist

- [ ] Goroutine lifecycle managed (no leaks)
- [ ] Channel directions (send/receive) restricted
- [ ] select with default for non-blocking
- [ ] sync.WaitGroup for goroutine coordination
- [ ] Context for cancellation and deadlines
- [ ] errgroup for error propagation

