Pipeline
The Pipeline design pattern is like having a team of experts working together to handle complex tasks. Each expert specializes in one part of the job, and they work simultaneously to get things done faster. Let’s explore this idea with an example.
Remember back in Chapter 4, Getting Familiar with Behavioral Patterns, when we talked about creating an HTML page parser? Back then, we assumed we already had the HTML pages to work with. Now, let’s design a process to create a never-ending stream of pages.
First, we need someone to fetch news pages from the internet every now and then. Think of this as our producer. In code, it looks like this:
fun CoroutineScope.producePages() = produce {
fun getPages(): List<String> {
// In reality, this would fetch pages from the web
return listOf(
"<html><body><h1>Cool stuff</h1></body></html>",
"<html><body...