Implement a Status Message with handle_call
The last callback we’ll cover is the handle_call. The handle_call is a two-way message, or a synchronous one. Use handle_call when you want to return a result to the client. This result may be nothing more than a simple :ok acknowledgement, or it may be much more. We’ll use handle_call to implement a :status feature, to get a list of all alarms.
Since a request to :status will require our server to send a message back to our client, we’ll need to use handle_call. Most of the status work will come in the functional core, our alarm.ex module.
Implement the Status in the Core
Since we are dealing with timers, the most important information to the user is the timer, how long it is, and how much time is left. ...
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.