This example uses KAR's Actor Programming Model to implement Dijkstra's solution to the Dining Philosophers problem (https://en.wikipedia.org/wiki/Dining_philosophers_problem).
The Philosophers and their Forks are all actors and interact via actor method invocations to implement the distributed protocol that ensures no Philosopher starves.
Philosophers use a tail call pattern to move from one state to the next and achieve fault tolerance.
A Cafe may contain an arbitrary number of tables of Philosophers. Each Cafe tracks its occupancy and generates messages when it seats new tables or when a sated Philosopher leaves.
To run the example locally, first do an npm install
.
Then in one window start up the server code:
kar run -app dp -actors Cafe,Table,Fork,Philosopher node philosophers.js
In a second window, use the kar
cli to invite some Philosopers to dinner:
# Invite 10 Philosophers to a meal of 20 servings each
kar invoke -app dp Cafe Cafe+de+Flore seatTable 10 20