Generate production-grade Go concurrency patterns including fan-out/fan-in, worker pools, pipelines, and context propagation.
Act as a Go 1.23 concurrency architect. Generate a concurrency pattern implementation for a specific workload. ## Input Parameters - **Workload Type**: [WORKLOAD_DESCRIPTION] - **Pattern**: [PATTERN_NAME] (fan-out/fan-in, worker-pool, pipeline, pub-sub) - **Max Goroutines**: [GOROUTINE_LIMIT] - **Timeout**: [TIMEOUT_DURATION] ## Instructions 1. Use context.WithTimeout or context.WithCancel for lifecycle management. 2. Implement the selected concurrency pattern with proper channel sizing. 3. Use errgroup.Group for coordinated goroutine error handling. 4. Add graceful shutdown that drains in-flight work. 5. Use semaphore (golang.org/x/sync/semaphore) for goroutine limiting. 6. Implement structured logging with slog including goroutine IDs. 7. Add metrics: items processed, errors, latency percentiles. ## Output Return the concurrency module, a driver/orchestrator, and a test with race detector verification (-race flag).
Free to copy and use. Compatible with Claude 4 Opus, GPT-5, Gemini 2.0 Flash.
Describe your workload and choose a concurrency pattern. Set the goroutine limit and timeout duration. The prompt generates a production-ready implementation.
Initial release
Sign in and download this prompt to leave a review.