ClawKit Logo
ClawKitReliability Toolkit
Back to Registry
Official Verified

go-concurrency

Production Go concurrency patterns — goroutines, channels, sync primitives, context, worker pools, pipelines, and graceful shutdown. Use when building concurrent Go applications or debugging race conditions.

skill-install — Terminal

Install via CLI (Recommended)

clawhub install openclaw/skills/skills/wpank/go-concurrency-patterns
Or

Go Concurrency Patterns

Production patterns for Go concurrency including goroutines, channels, synchronization primitives, and context management.

When to Use

  • Building concurrent Go applications
  • Implementing worker pools and pipelines
  • Managing goroutine lifecycles and cancellation
  • Debugging race conditions
  • Implementing graceful shutdown

Concurrency Primitives

PrimitivePurposeWhen to Use
goroutineLightweight concurrent executionAny concurrent work
channelCommunication between goroutinesPassing data, signaling
selectMultiplex channel operationsWaiting on multiple channels
sync.MutexMutual exclusionProtecting shared state
sync.WaitGroupWait for goroutines to completeCoordinating goroutine completion
context.ContextCancellation and deadlinesRequest-scoped lifecycle management
errgroup.GroupConcurrent tasks with errorsParallel work that can fail

Go Concurrency Mantra: Don't communicate by sharing memory; share memory by communicating.

Quick Start

func main() {
    ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
    defer cancel()

    results := make(chan string, 10)
    var wg sync.WaitGroup

    for i := 0; i < 3; i++ {
        wg.Add(1)
        go func(id int) {
            defer wg.Done()
            select {
            case <-ctx.Done():
                return
            case results <- fmt.Sprintf("Worker %d done", id):
            }
        }(i)
    }

    go func() { wg.Wait(); close(results) }()

    for result := range results {
        fmt.Println(result)
    }
}

Pattern 1: Worker Pool

type Job struct {
    ID   int
    Data string
}

type Result struct {
    JobID  int
    Output string
    Err    error
}

func WorkerPool(ctx context.Context, numWorkers int, jobs <-chan Job) <-chan Result {
    results := make(chan Result)
    var wg sync.WaitGroup

    for i := 0; i < numWorkers; i++ {
        wg.Add(1)
        go func() {
            defer wg.Done()
            for job := range jobs {
                select {
                case <-ctx.Done():
                    return
                default:
                    results <- Result{
                        JobID:  job.ID,
                        Output: fmt.Sprintf("Processed: %s", job.Data),
                    }
                }
            }
        }()
    }

    go func() { wg.Wait(); close(results) }()
    return results
}

// Usage
func main() {
    ctx, cancel := context.WithCancel(context.Background())
    defer cancel()

Metadata

Author@wpank
Stars919
Views1
Updated2026-02-12
View Author Profile
AI Skill Finder

Not sure this is the right skill?

Describe what you want to build — we'll match you to the best skill from 16,000+ options.

Find the right skill
Add to Configuration

Paste this into your clawhub.json to enable this plugin.

{
  "plugins": {
    "official-wpank-go-concurrency-patterns": {
      "enabled": true,
      "auto_update": true
    }
  }
}
Safety NoteClawKit audits metadata but not runtime behavior. Use with caution.