...

/

GenServer Callbacks: handle_info

GenServer Callbacks: handle_info

Learn how the GenServer uses handle_cast to interact with processes.

The handle_info callback function

Other than using GenServer.cast/2 and GenServer.call/3, we can also send a message to a process using Process.send/2. This generic message triggers the handle_info/2 callback, which works exactly like handle_cast/2 and can return the same set of tuples. Usually, handle_info/2 deals with system messages. Normally, we expose our server API using cast/2 and call/2 and keep send/2 for internal use.

Implement retries for failed emails

Let’s see how we can use handle_info/2. We’ll implement retries for emails that fail to send. To test this, we need to modify sender.ex, so one of the emails returns an error. We replace our ...