go-concurrencylisted
Install: claude install-skill dwana1/golang-skills
# Go Concurrency
This skill covers concurrency patterns and best practices from Google's Go Style
Guide and Uber's Go Style Guide, including goroutine management, channel usage,
mutex handling, and synchronization.
---
## Goroutine Lifetimes
> **Normative**: When you spawn goroutines, make it clear when or whether they
> exit.
### Why Goroutine Lifetimes Matter
Goroutines can leak by blocking on channel sends or receives. The garbage
collector **will not terminate** a goroutine blocked on a channel even if no
other goroutine has a reference to the channel.
Even when goroutines do not leak, leaving them in-flight when no longer needed
causes:
- **Panics**: Sending on a closed channel causes a panic
- **Data races**: Modifying still-in-use inputs after the result isn't needed
- **Memory issues**: Unpredictable memory usage from long-lived goroutines
- **Resource leaks**: Preventing unused objects from being garbage collected
```go
// Bad: Sending on closed channel causes panic
ch := make(chan int)
ch <- 42
close(ch)
ch <- 13 // panic
```
### Make Lifetimes Obvious
Write concurrent code so goroutine lifetimes are evident. Keep
synchronization-related code constrained within function scope and factor logic
into synchronous functions.
```go
// Good: Goroutine lifetimes are clear
func (w *Worker) Run(ctx context.Context) error {
var wg sync.WaitGroup
for item := range w.q {
wg.Add(1)
go func() {
defer wg.Done()
process(ctx,