下載技能 ZIP
在 Claude 中上傳
前往 設定 → 功能 → 技能 → 上傳技能
開啟並開始使用
測試它
正在使用「go-concurrency-patterns」。 Suggest a pattern for processing many jobs with cancellation.
預期結果:
- Use a worker pool with a buffered jobs channel
- Pass a context to stop workers on cancel
- Close results channel after all workers finish
- Add errgroup when you need early failure on error
正在使用「go-concurrency-patterns」。 How do I run multiple functions in parallel and wait for all?
預期結果:
- Use sync.WaitGroup to wait for goroutines
- Add each goroutine with wg.Add(1) before spawning
- Call wg.Done() in each goroutine defer
- Block with wg.Wait() after starting all goroutines
正在使用「go-concurrency-patterns」。 What happens if I close a channel from the receiver side?
預期結果:
- It causes a panic
- Only close channels from the sender side
- Or use a separate goroutine dedicated to closing
- Check if channel is open before sending
安全審計
安全All 58 static findings are FALSE POSITIVES. The scanner matched substrings without semantic context: 'C2' from 'close()', 'weak crypto' from 'WaitGroup', 'dynamic import' from Go import statements, 'backtick execution' from markdown code formatting, and 'path traversal' from code comments. This is a pure documentation skill containing only markdown and JSON files with Go code examples. No executable code, no network calls beyond documentation links, no filesystem access beyond its own files.
風險因素
品質評分
你能建構什麼
设计并发服务
为生产服务选择工作池、管道和取消模式。
规划优雅关闭
为长时间运行的进程添加安全的关闭和超时处理。
理解并发基础
通过清晰的示例学习 goroutine、通道和同步。
試試這些提示
用一个小示例为初学者解释 goroutine 和通道。
在 Go 中提供一个带有上下文取消、工作通道和结果通道的工作池模式。
展示使用上下文和操作系统信号的优雅关闭模式,并附上简短说明。
比较信号量和 errgroup 限制模式,并为 API 获取任务推荐一种。
最佳實務
- 在所有并发操作中使用上下文进行取消和截止时间管理
- 仅从发送端关闭通道以避免 panic
- 确保 goroutine 有明确的退出路径并定期检查 ctx.Done
避免
- 使用 time.Sleep 进行同步而非正确的原语
- 从接收端关闭通道导致 panic
- 在长时间运行的循环中忽略 ctx.Done 导致 goroutine 泄漏