Re:Go 1.18
by sriram_malhar on Wednesday March 16, 2022 @12:07AM
(#30695211)
Erlang doesn't have priorities natively, does it? As far as I am aware, there is a standard pattern to do it, like this:
The Go equivalent can be done with different channels for priorities and similarly nested selects, as I am sure you are aware.
[ Parent
| on HN ]
Erlang has selective receive, meaning it will go through all your receive branches in order, until one matches.
With this code:
receive
{high_p, Message} ->
process_high(Message);
{low_p, Message} ->
process_low(Message)
end
if the process has one high_p message and a low_p message, the high_p message will be processed first.Hm, is this pattern the best Erlang has and VM does not optimize it to avoid the need to lock the queue twice? If so then you are right double-select is equivalent even if it is rather messier in Go then in Erlang with the need to provide 2 channels.