September 2013
Intermediate to advanced
548 pages
12h 25m
English
When we write our application, we need only one alarm—we’ll raise it when the CPU starts melting because we’re computing a humongous prime (remember, we were making a company that sells prime numbers). This time we’ll use the real OTP alarm handler (and not the simple one we saw at the start of this chapter).
The alarm handler is a callback module for the OTP
gen_event behavior. Here’s the code:
| my_alarm_handler.erl | |
| | -module(my_alarm_handler). |
| | -behaviour(gen_event). |
| | |
| | %% gen_event callbacks |
| | -export([init/1, code_change/3, handle_event/2, handle_call/2, |
| | handle_info/2, terminate/2]). |
| | |
| | %% init(Args) must return {ok, State} |
| | init(Args) -> |
| | io:format("*** my_alarm_handler init:~p~n",[Args]), |
| | {ok, 0}. |
| | |
| | handle_event({set_alarm, ... |
Read now
Unlock full access