I'm new to Erlang and I want to suspend in a function. I use receive with infinity timeout, my function looks like:
suspend() ->
receive
after
infinity->ok
end.
When I ran dialyzer tool, it return "Function has no local return". Should I replace this function with timer:sleep(infinity). For suspend, which one is better? Thank you so much.
The function timer:sleep/1
is defined as:
sleep(T) ->
receive
after T -> ok
end.
which is essentially the same as your suspend/0
function, so either approach would work. I'd advise using timer:sleep/1
, though, as it's already defined for you, and anyone reading it will instantly know what it is and what it does.