Implement Go concurrency patterns using goroutines, channels, and synchronization primitives. Use when building concurrent systems, implementing parallelism, or managing goroutine lifecycles. Trigger words include "goroutine", "channel", "concurrent", "parallel", "sync", "context".
View on GitHubarmanzeroeight/fastagent-plugins
go-toolkit
January 21, 2026
Select agents to install to:
npx add-skill https://github.com/armanzeroeight/fastagent-plugins/blob/main/plugins/go-toolkit/skills/goroutine-patterns/SKILL.md -a claude-code --skill goroutine-patternsInstallation paths:
.claude/skills/goroutine-patterns/# Goroutine Patterns
Implement Go concurrency patterns for efficient parallel processing.
## Quick Start
**Basic goroutine:**
```go
go func() {
// Runs concurrently
}()
```
**With channel:**
```go
ch := make(chan int)
go func() {
ch <- 42
}()
result := <-ch
```
## Instructions
### Step 1: Choose Concurrency Pattern
**Simple parallel execution:**
```go
var wg sync.WaitGroup
for i := 0; i < 10; i++ {
wg.Add(1)
go func(id int) {
defer wg.Done()
process(id)
}(i)
}
wg.Wait()
```
**Worker pool:**
```go
jobs := make(chan Job, 100)
results := make(chan Result, 100)
// Start workers
for w := 0; w < numWorkers; w++ {
go worker(jobs, results)
}
// Send jobs
for _, job := range allJobs {
jobs <- job
}
close(jobs)
// Collect results
for range allJobs {
result := <-results
handleResult(result)
}
```
**Pipeline:**
```go
// Stage 1: Generate
gen := func() <-chan int {
out := make(chan int)
go func() {
defer close(out)
for i := 0; i < 10; i++ {
out <- i
}
}()
return out
}
// Stage 2: Process
process := func(in <-chan int) <-chan int {
out := make(chan int)
go func() {
defer close(out)
for n := range in {
out <- n * 2
}
}()
return out
}
// Use pipeline
for result := range process(gen()) {
fmt.Println(result)
}
```
### Step 2: Implement Channel Communication
**Unbuffered channel (synchronous):**
```go
ch := make(chan int)
go func() {
ch <- 42 // Blocks until received
}()
value := <-ch // Blocks until sent
```
**Buffered channel (asynchronous):**
```go
ch := make(chan int, 10) // Buffer of 10
ch <- 1 // Doesn't block until buffer full
ch <- 2
value := <-ch // Doesn't block if buffer has data
```
**Select for multiple channels:**
```go
select {
case msg := <-ch1:
fmt.Println("Received from ch1:", msg)
case msg := <-ch2:
fmt.Println("Received from ch2:", msg)
case <-time.After(time.Second):