Skip to content

Add support for elixir 1.7's handle_continue/2 #47

Description

@archseer

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions