Message Priority: The Naive Approach
- Use one receive statement to handle all the priority messages...
loop(Value) ->
NewValue = handle_all_priority_messages(Value),
Value2 = handle_one_non_priority_message(NewValue),
loop(Value2).
handle_all_priority_messages(Value) ->
receive
{increment_value, FromId, Amt} ->
NewValue = Value + Amt,
FromId ! {increment_value, self(), NewValue},
handle_all_priority_messages(NewValue);
{increment_value, FromId} ->
IncValue = Value + 1,
FromId ! {increment_value, self(), IncValue},
handle_all_priority_messages(IncValue)
after
0 -> Value
end.