Scatter / Gather (3 of 4)
- Add a timeout to the receive statement
gather(0, Results) ->
Results;
gather(Count, Results) ->
receive
{Pid, Item, Result} -> gather(Count-1, [{Item, Result} | Results])
after
3000 -> Results
end.
- The current set of results are considered complete
- Exercise: Use the TimeRemaining approach for the timeout
- Unfortunately its messages will get stuck in the queue
- Worse yet, we might accidentally collect them next time we call gather