funbox/smppex

Add support for elixir 1.7's handle_continue/2

archseer opened this issue · 1 comments

https://michal.muskala.eu/2018/06/20/my-otp-21-highlights.html#new-callback-in-genserver-handle_continue2

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

Hello!

Nice idea, I think.