handle_info Processes Nonstandard Messages

You’ve seen a brief introduction of handle_info, but now we can fill in some more details. Use the handle_info callback to send generic Elixir messages to a GenServer. By generic, we mean messages that work with any generic Elixir process, not necessarily a GenServer process.

Elixir uses the actor programming model, meaning each process has its own message queue. You can use process primitives to send messages to any Elixir process, as long as you have a pid.

Sometimes, you may want your GenServer to receive messages from Elixir or Erlang process primitives rather than calls or casts built for OTP. A good example is the Process.send_after/2 function. Let’s see how that works.

Send a Timed Message

As you ...

Get Programmer Passport: OTP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.