Fan Out
The goal of the Fan Out design pattern is to distribute work between multiple concurrent processors, also known as workers. To understand it better, let's look again at the previous section but consider the following problem:
What if the amount of work at the different steps in our pipeline is very different?
For example, it takes a lot more time to fetch the HTML content than to parse it. In such a case, we may want to distribute that heavy work between multiple coroutines. In the previous example, only a single coroutine was reading from each channel. But multiple coroutines can consume from a single channel too, thus dividing the work.
To simplify the problem we're about to discuss, let's have only one coroutine producing some results:
fun CoroutineScope.generateWork() = produce { for (i in 1..10_000) { send("page$i") } &...