Add support for elixir 1.7's handle_continue/2
archseer opened this issue · 1 comments
archseer commented
handle_continue was added to OTP 21 primarily to support asynchronous setup without blocking (this way we can run code right after init, but make sure start_link doesn't timeout or error).
Would be extremely useful to be able to bind right after init.
At the moment we do something like
def init(...) do
...
Kernel.send(self(), :bind)
{:ok, %{}}
end
def handle_info(:bind, st) do
pdu = bind(....)
{:noreply, [pdu], st}
end
Which is definitely not ideal (I remember I had to hack around a bit because certain sends wouldn't allow sending to self at all).
With the new GenServer callbacks, this would look like:
def init(...) do
...
{:ok, %{}, {:continue, :bind}}
end
def handle_continue(:bind, st) do
pdu = bind(....)
{:noreply, [pdu], st}
end
savonarola commented
Hello!
Nice idea, I think.