Pipeline
The Pipeline design pattern allows us to scale heterogeneous work, consisting of multiple steps of varying complexity across multiple CPUs, by breaking the work into smaller, concurrent pieces. Let's look at the following example to understand it better.
Back in Chapter 4, Getting Familiar with Behavioral Patterns, we wrote an HTML page parser. It was assumed that the HTML pages themselves were already fetched for us, though. What we would like to design now is a process that would create a possibly infinite stream of pages.
First, we would like to fetch news pages once in a while. For that, we'll have a producer:
fun CoroutineScope.producePages() = produce { fun getPages(): List<String> { // This should actually fetch something return listOf( "<html>...