I want to do a selective receive where a record property needs to be matched, but whatever syntax I try, I get an "illegal pattern" message.
loop(State) ->
receive
{response, State#s.reference} -> do_something()
end.
Is this not possible?
Just an alternative which uses pattern matching:
loop(#s{reference = Reference} = State) ->
receive
{response, Reference} ->
do_something()
end.
loop(State) ->
receive
{response, R} when R =:= State#s.reference ->
do_something()
end.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With