Generic Event Handling

An event is just something that happens—something noteworthy that the programmer thinks somebody should do something about.

When we’re programming and something noteworthy happens, we just send an event message to a registered process, like this:

 
RegProcName ! {event, E}

E is the event (any Erlang term). RegProcName is the name of a registered process.

We don’t know (or care) what happens to the message after we have sent it. We have done our job and told somebody else that something has happened.

Now let’s turn our attention to the process that receives the event messages. This is called an event handler. The simplest possible event handler is a “do nothing” handler. When it receives an {event, X} message, it does ...

Get Programming Erlang, 2nd Edition 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.