Coordination
Futures work well for cases like the crowdspell
example. Work is assigned to a thread; the thread performs its task independently and returns a result to the initial thread. The coordination is in the gathering of the results: evaluation is blocked until all the futures have completed. Thanks to immutability, there is a guarantee that simultaneous threads won't interfere with each other because nothing is shared.
This simple model is effective precisely because it is simple. Sometimes, however, more coordination is necessary, especially when communication between threads is required.
With a future, we fork, perform a computation, and return the data:
Message sending is one way to communicate among threads. Now, we imagine three threads that send messages to one another:
To...