Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
archseer opened this issue Aug 7, 2018 · 1 comment
Open

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

archseer opened this issue Aug 7, 2018 · 1 comment
Assignees

Comments

@archseer
Copy link
Contributor

archseer commented Aug 7, 2018

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
@savonarola
Copy link
Contributor

Hello!

Nice idea, I think.

@savonarola savonarola self-assigned this Aug 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants