go-concurrency-patterns

Provide idiomatic Go examples for advanced concurrency patterns.

38.6k|4.1k|Updated Jul 24, 2025
One-click install
npx skills add https://github.com/wshobson/agents --skill go-concurrency-patterns-wshobson
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-concurrency-patterns
Source: https://github.com/wshobson/agents/tree/main/plugins/systems-programming/skills/go-concurrency-patterns
Command: npx skills add https://github.com/wshobson/agents --skill go-concurrency-patterns-wshobson

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires golang.org/x/sync/semaphore, golang.org/x/sync/errgroup, and includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill provides practical, production-ready patterns for writing efficient and robust concurrent Go applications, helping developers avoid common pitfalls like race conditions and deadlocks.

Core Features & Use Cases

  • Concurrency Primitives: Demonstrates effective use of goroutines, channels, select, sync.Mutex, sync.WaitGroup, and context.Context.
  • Key Patterns: Includes implementations for Worker Pools, Fan-Out/Fan-In pipelines, Rate Limiting, Graceful Shutdown, Error Groups, and Concurrent Maps.
  • Use Case: When building a web server that needs to handle many requests concurrently, you can use the Worker Pool pattern to manage a fixed number of goroutines processing incoming requests, ensuring efficient resource utilization.

Quick Start

Use the go-concurrency-patterns skill to implement a worker pool that processes 10 jobs concurrently.

Frequently Asked Questions about go-concurrency-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement a worker pool in Go to process jobs concurrently?

To implement a worker pool in Go, you use goroutines and channels to manage a fixed number of workers processing jobs concurrently. This pattern ensures efficient resource utilization by limiting the number of active goroutines processing incoming requests.

What is the best way to handle errors across multiple goroutines in Go?

Handling errors across multiple goroutines is best done using an error group to collect and propagate failures. The errgroup package synchronizes concurrent operations and returns the first critical error, ensuring reliable concurrent system behavior.

How do I gracefully shutdown goroutines when processing background tasks?

You gracefully shutdown goroutines by using context cancellation alongside channels and sync.WaitGroup. This signals active workers to stop processing, allowing them to finish current tasks and release resources without causing deadlocks.

Can I use channels to rate limit concurrent API requests in Go?

You can use channels and a ticker to rate limit concurrent API requests in Go. This pattern controls the flow of goroutines accessing external services, preventing resource exhaustion and ensuring reliable concurrent system performance.

What is the fan-out fan-in pattern for Go concurrency?

The fan-out fan-in pattern distributes work across multiple goroutines and then aggregates their results into a single channel. This approach maximizes parallelism by splitting tasks and collecting outputs, solving challenges in building scalable concurrent pipelines.