# Elixir's gen\_event Behavior and Its Event Manager and Handler Design

DevFeed: [Elixir's gen\_event Behavior and Its Event Manager and Handler Design](<https://devfeed.tech/articles/what-is-wrong-with-gen-event-22359.md>)

Original publisher: [Read original article](<http://www.afronski.pl/2015/11/02/what-is-wrong-with-gen-event.html>)

Author: Wojtek Gawroński (afronski)

Published: 2015-11-02T15:00:00Z

Content type: opinion

Language: en

Sources: [Wojtek Gawroński](<https://devfeed.tech/sources/wojtek-gawronski.md>)

Topics: [Elixir](<https://devfeed.tech/topics/elixir.md>), [modules](<https://devfeed.tech/topics/modules.md>), [Processes](<https://devfeed.tech/topics/processes.md>), [Concurrency](<https://devfeed.tech/topics/concurrency.md>), [Simulation](<https://devfeed.tech/topics/simulation.md>)

Tags: [c-sharp](<https://devfeed.tech/tags/c-sharp.md>), [canvas](<https://devfeed.tech/tags/canvas.md>), [clojure](<https://devfeed.tech/tags/clojure.md>), [concurrency](<https://devfeed.tech/tags/concurrency.md>), [console](<https://devfeed.tech/tags/console.md>), [css](<https://devfeed.tech/tags/css.md>), [css3](<https://devfeed.tech/tags/css3.md>), [elixir](<https://devfeed.tech/tags/elixir.md>), [erlang](<https://devfeed.tech/tags/erlang.md>), [handler](<https://devfeed.tech/tags/handler.md>), [html](<https://devfeed.tech/tags/html.md>), [html5](<https://devfeed.tech/tags/html5.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [module](<https://devfeed.tech/tags/module.md>), [mono](<https://devfeed.tech/tags/mono.md>), [net](<https://devfeed.tech/tags/net.md>), [node-js](<https://devfeed.tech/tags/node-js.md>), [process](<https://devfeed.tech/tags/process.md>), [sicp](<https://devfeed.tech/tags/sicp.md>), [vagrant](<https://devfeed.tech/tags/vagrant.md>), [webgl](<https://devfeed.tech/tags/webgl.md>)

## AI overview

This article examines Elixir's gen_event behavior, explaining how event managers receive events and dispatch them to installed handler modules. It presents the design as a pattern the author considers problematic, while noting that the article dates from 2015 and that Elixir has changed since then.

## Source excerpt

Beware: this article is from 2015 and in Elixir world couple things changed a bit. Here you can find the updated version of this blog post. What is wrong with gen_event? I never used gen_event, I think it is a bad pattern. At first it may look like a controversial statement, but I heard a lot of those complaints from other people. Originally, I heard that exact statement during the presentation made by Garrett Smith about pattern language - someone asked about that behavior at the end. More recently I heard similar thing in José Valim's presentation about what will come next in Elixir. It confuses me every time I hear that, so I want to investigate topic more deeply. But before we will dive into reasons and explanations, let's recall what is the purpose of this behavior. What is gen_event? OTP introduces two different terms regarding that behavior - an event manager and event handler modules. Responsibility of event manager is being a named object which can receive events. An event can be, for example: an error, an alarm, or some information that is to be logged. Inside manager we can have 0, 1 or more event handlers installed. Responsibility of the handler is to process an event. When the event manager is notified about an event, it will be processed by all installed handlers. The easiest way to imagine that is to think about manager as a sink for incoming messages and handlers as different implementations which are writing messages to disk, database or terminal. Another example can be taken from my implementation of Francesco Cesarini's assignment called Wolves, Rabbits and Carrots simulation. Main purpose of that task is to introduce concurrency, but internally it is a simulation - so certain events are happening, and they will be broadcasted to the rest of entities. In that case simulation_event_stream is an event manager: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 -module(simulation_event_stream). -export([ start_link/0, co