Another pattern we can easily implement using Akka is CountDownLatch. The basic behavior of a latch is to wait until the count has reached zero in order to allow another action to happen. This is normally referred to as "to open the gate". The idea is to have some processing tasks running in other threads or services and wait until all of them have been completed. This pattern has multiple use cases. For example, it can be used to aggregate some elements into a single unit similarly in order to have what we implemented in the previous recipe, The aggregator pattern.
In this recipe, we will demonstrate how to create a CountDownLatch actor and use it to wait until some other processing tasks are happening in other actors. We will implement two approaches: Future and Await.