Asynchronous programming is a very good choice for making independent processes collaborate, relieving the designer from the burden of maintaining a global state for all of the entities at stake. We are going to showcase this in a recipe, in which we will simulate an online taxi-booking engine.
In the system we are longing to build, no global state will be maintained. Instead, we are going to fire as many processes as we have taxis, and a couple more to ensure that the collaboration between them occurs properly. Finally, customer requests will land in our system from the outer world via channels.
The rules our taxi-booking engine obeys will be kept as simple as possible a given taxi, whose status is initially :free
, keeps moving randomly around town unless it receives from headquarters a customer request that matches the place it happens to be in at that particular moment. Then, it notifies headquarters that it is willing to process that particular request...