Build concurrent Go applications with confidence. Learn production-ready patterns for goroutines, channels, worker pools, and graceful shutdown to avoid race conditions and resource leaks.
下載技能 ZIP
在 Claude 中上傳
前往 設定 → 功能 → 技能 → 上傳技能
開啟並開始使用
測試它
正在使用「go-concurrency-patterns」。 Create a worker pool with 3 workers that processes jobs from a channel
預期結果:
Here's a worker pool implementation with 3 workers that processes jobs concurrently and collects results through a results channel with proper synchronization using sync.WaitGroup.
正在使用「go-concurrency-patterns」。 Show me how to use errgroup for concurrent HTTP requests
預期結果:
This example demonstrates golang.org/x/sync/errgroup to fetch multiple URLs concurrently where the first error cancels all pending requests through context propagation.
正在使用「go-concurrency-patterns」。 Implement a semaphore to limit concurrent operations
預期結果:
I provide two semaphore approaches: using golang.org/x/sync/semaphore.Weighted for weighted semaphores and a channel-based struct{} semaphore for simple rate limiting.
安全審計
安全All 44 static analysis findings are false positives from markdown-enclosed Go code examples. The skill contains legitimate educational content about Go concurrency patterns with no executable code or security risks.
品質評分
你能建構什麼
Build concurrent microservices
Create scalable Go services with worker pools that handle multiple requests concurrently while managing resources efficiently
Implement data processing pipelines
Design fan-out/fan-in pipelines to process large datasets in parallel with proper error handling and cancellation
Debug race conditions
Identify and fix concurrency bugs in existing Go code using proper synchronization patterns and race detection tools
試試這些提示
Show me how to create a worker pool in Go that processes 100 jobs with 5 concurrent workers
Write a Go server with graceful shutdown that handles SIGTERM signals and waits for in-flight requests to complete
Create a fan-out/fan-in pipeline in Go that processes items through 3 stages with 5 workers per stage
Review this Go code and identify potential goroutine leaks, then show me how to fix them using context cancellation
最佳實務
- Always use context.Context for cancellation and deadlines in concurrent operations
- Close channels only from the sender side to avoid panics
- Prefer channels over mutexes for communication between goroutines
- Use sync.WaitGroup or errgroup to wait for goroutine completion
避免
- Using time.Sleep for synchronization instead of proper primitives like channels or WaitGroup
- Closing channels from the receiver side which causes panic
- Forgetting to check ctx.Done() which leads to goroutine leaks
- Sharing memory between goroutines without proper synchronization