Upgrade to Pro — share decks privately, control downloads, hide ads and more …

BEAM Architecture Handbook

BEAM Architecture Handbook

Andrea Leopardi

May 26, 2019
Tweet

More Decks by Andrea Leopardi

Other Decks in Programming

Transcript

  1. def handle_info(:some_message, state) do # ... end def handle_info(:other_message, state)

    do # ... end def handle_info(unknown, state) do Logger.warn("Unknown message") {:noreply, state} end
  2. defmodule MyAppWeb.Controller do use MyAppWeb, :controller def show(conn, %{"id" =>

    id}) do case Integer.parse(id) do {id, ""} -> # ... _other -> send_resp(conn, 400, "bad id") end end end
  3. Node.monitor(consumer_node, true) monitor_ref = Process.monitor(consumer_pid) send(consumer_pid, {monitor_ref, message}) receive do

    {:ack, ^monitor_ref} -> Process.demonitor(monitor_ref, [:flush]) {:DOWN, ^monitor_ref, _, _, _} -> give_to_another_consumer(message) {:nodedown, ^consumer_node} -> give_to_another_consumer(message) end