This chapter covers
- Designing synchronous APIs that treat concurrency as an implementation detail
- Standardizing the processing of sequences of values using push iterators
- Structuring concurrent processing with the pipeline pattern
Having finished the HIT tool, we can focus on the HIT client within the hit
package. It allows our tool to send concurrent requests to measure HTTP server performance.
HTTP provides a realistic context for the concurrency patterns we’ll discuss in this chapter, helping us see how and where to use them. Because these patterns apply broadly—not only to HTTP—I’ll save HTTP-specific details for chapter 7 to keep the focus strictly on concurrency.
As chapter 1 hinted, channels use a message-passing approach that simplifies concurrent programming by making the data flow between goroutines explicit. This chapter dives into the concurrent pipeline pattern to demonstrate this approach in practice.
The hit
package will show us how to structure a straightforward package API that appears to be synchronous from the outside but runs concurrently inside. We’ll begin with a package that works sequentially and refactor it to work concurrently without changing its exported API. By chapter’s end, you’ll learn how to structure concurrent code effectively in Go.