go-concurrency-patterns

Manage goroutine lifecycles and safe concurrent communication in Go applications.

905|126|Updated Jan 27, 2023
One-click install
npx skills add https://github.com/carrot-hu23/dst-admin-go --skill go-concurrency-patterns-carrot-hu23
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-concurrency-patterns
Source: https://github.com/carrot-hu23/dst-admin-go/tree/main/.claude/skills/go-concurrency-patterns
Command: npx skills add https://github.com/carrot-hu23/dst-admin-go --skill go-concurrency-patterns-carrot-hu23

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Concurrent Go programs are hard to get right: goroutine leaks, race conditions, improper cancellation, and unbounded parallelism can cause instability, resource exhaustion, and subtle bugs. This Skill consolidates proven patterns and best practices to coordinate goroutines, manage communication, and implement safe shutdowns so systems remain responsive and maintainable.

Core Features & Use Cases

  • Worker pool and pipeline patterns for processing jobs concurrently while controlling throughput.
  • Fan-out/fan-in and merge strategies to compose parallel stages with context-aware cancellation.
  • Bounded concurrency and semaphore patterns to limit resource usage and rate of work.
  • Graceful shutdown and errgroup-based coordination to cancel work on error or signal and collect results.
  • Race detection and concurrent map strategies for safe shared-state access in high-read or write-heavy scenarios.
  • Use Case: Convert a monolithic background processor into a cluster-friendly service with cancellable workers, limited concurrency, and deterministic shutdown.

Quick Start

Use the go-concurrency-patterns skill to design or review a Go service that requires worker pools, context cancellation, bounded concurrency, and graceful shutdown.

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 with graceful shutdown?

Worker pools in Go with graceful shutdown use goroutines and channels to process jobs concurrently while context-based cancellation ensures safe termination. Bounded concurrency limits resource usage, and errgroup coordination collects results and cancels work on signal or error.

How do I prevent goroutine leaks in Go concurrent programs?

Preventing goroutine leaks in Go requires context-based cancellation and proper synchronization primitives to coordinate goroutine lifecycles. Fan-in/fan-out pipeline patterns with context-aware cancellation ensure all goroutines exit cleanly when work completes or errors occur.

What is the best way to limit concurrency and control throughput in Go?

Bounded concurrency and semaphore patterns in Go limit resource usage and rate of work by restricting the number of active goroutines. Worker pool patterns process jobs concurrently while controlling throughput to prevent resource exhaustion in server backends.

How does errgroup coordination work for fan-out/fan-out pipelines in Go?

Errgroup coordination in Go manages fan-out/fan-in pipelines by composing parallel stages with context-aware cancellation. It cancels remaining work on error and collects results, enabling deterministic shutdown for background tasks and concurrent processing stages.

Can I use race detection for safe shared-state access in Go concurrent programs?

Race detection in Go identifies race conditions in concurrent programs to ensure safe shared-state access. Concurrent map strategies provide safe alternatives for high-read or write-heavy scenarios, preventing subtle bugs from improper synchronization.

When do I need context-based cancellation in Go server backends?

Context-based cancellation in Go server backends is needed for graceful shutdown, worker pool termination, and background task coordination. It ensures goroutines respond to signals or errors by exiting cleanly, preventing resource exhaustion and maintaining responsiveness.