Set up targets manually. Notice how both Baristas are concurrently processing different orders. This is closer to what we want. The select expression suspends if none of the channels are ready. How can we change our program so the Baristas can steam the milk while pulling a shot of espresso? But I personally find that it’s not that difficult to close the Channel when your consumer is not listening with the Android lifecycle for example you know exactly when your consumer is paused or dead and the only thing that you need to do is call .close() on the Channel instance. The operating system schedules a slice of time for each thread to run. We can launch a coroutine for each portafilter and associate each portafilter with a channel. The Barista: 1. Kotlin is a new programming language from JetBrains, the maker of the world’s best IDEs.After much searching, I have settled on it as the programming language I will probably use for the next 5–10 years or so. Spring. This is typically how threads communicate — through shared memory. Add dependencies. That also means there’s no scheduler overhead. The second thing we did is add the suspend modifier to the makeCoffee function. And because this is a single thread program, the current function has to complete before moving on to the next function. All notifications in a channel are grouped together, and users can configure notification settings for a whole channel. And for now, let’s assume that we have two Coffee Grinders and our Espresso Machine can pull two shots at once. Corda is an open-source distributed ledger platform, supported by major banks, and built entirely in Kotlin. They are used mainly for messaging and synchronizing between coroutines (and behind the scenes of Flow). The above example starts two coroutines from main. What if we never closed the channel? A typical usage of the actor builder looks like this: val c = actor { // initialize actor's state for (msg in channel) { // process message here } } // send messages to the actor c.send(...) ... // stop the actor when it is no longer needed c.close() First thing to note is that we created an event channel in the socket. We looked at a few different patterns on how to share data and communicate across coroutines. This signals to the functions reading from that channel that there is nothing left to process. To answer that, let’s first refresh what threads are. If the receiving coroutine can’t keep up with producer, the producer overwrites the last item in the buffer. They’re managed at the user space level by the Kotlin Runtime. But the concepts certainly make reasoning about concurrency simpler. Channels and coroutines are no silver bullet for avoiding the familiar concurrency problems. This is why a coroutine is suspended until both the receiving and sending coroutines come together at the same time to transfer the data.val channel = Channel