Sophie

Sophie

distrib > Mageia > 7 > i586 > media > core-release > by-pkgid > 016232f1d9a3f7bee85855d35a2bca58 > files > 66

elixir-doc-1.7.2-1.mga7.noarch.rpm

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="generator" content="ExDoc v0.19.1">
    <title>GenEvent – Elixir v1.7.2</title>
    <link rel="stylesheet" href="dist/app-240d7fc7e5.css" />
      <link rel="canonical" href="https://hexdocs.pm/elixir/v1.7/GenEvent.html" />
    <script src="dist/sidebar_items-cdf4e58b19.js"></script>
    
  </head>
  <body data-type="modules">
    <script>try { if(localStorage.getItem('night-mode')) document.body.className += ' night-mode'; } catch (e) { }</script>
    <div class="main">
<button class="sidebar-button sidebar-toggle">
  <span class="icon-menu" aria-hidden="true"></span>
  <span class="sr-only">Toggle Sidebar</span>
</button>
<button class="sidebar-button night-mode-toggle">
  <span class="icon-theme" aria-hidden="true"></span>
  <span class="sr-only">Toggle Theme</span>
</button>
<section class="sidebar">

  <a href="http://elixir-lang.org/docs.html" class="sidebar-projectLink">
    <div class="sidebar-projectDetails">
      <h1 class="sidebar-projectName">
Elixir      </h1>
      <h2 class="sidebar-projectVersion">
        v1.7.2
      </h2>
    </div>
      <img src="assets/logo.png" alt="Elixir" class="sidebar-projectImage">
  </a>

  <form class="sidebar-search" action="search.html">
    <button type="submit" class="search-button">
      <span class="icon-search" aria-hidden="true"></span>
    </button>
    <input name="q" type="text" id="search-list" class="search-input" placeholder="Search" aria-label="Search" autocomplete="off" />
  </form>

  <ul class="sidebar-listNav">
    <li><a id="extras-list" href="#full-list">Pages</a></li>

      <li><a id="modules-list" href="#full-list">Modules</a></li>

      <li><a id="exceptions-list" href="#full-list">Exceptions</a></li>

  </ul>
  <div class="gradient"></div>
  <ul id="full-list" class="sidebar-fullList"></ul>
</section>

<section class="content">
  <div class="content-outer">
    <div id="content" class="content-inner">


      <h1>
        <small class="visible-xs">Elixir v1.7.2</small>
GenEvent <small>behaviour</small>        
          <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/elixir/lib/gen_event.ex#L1" title="View Source" class="view-source" rel="help">
            <span class="icon-code" aria-hidden="true"></span>
            <span class="sr-only">View Source</span>
          </a>
      </h1>

        <div class="deprecated">
          This behaviour is deprecated. Use Erlang/OTP's :gen_event module instead.
        </div>

        <section id="moduledoc">
<p>A event manager with event handlers behaviour.</p>
<p>If you are interested in implementing an event manager, please read the
“Alternatives” section below. If you have to implement an event handler to
integrate with an existing system, such as Elixir’s Logger, please use
<code class="inline">:gen_event</code> instead.</p>
<h2 id="module-alternatives" class="section-heading">
  <a href="#module-alternatives" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
  Alternatives
</h2>

<p>There are a few suitable alternatives to replace GenEvent. Each of them can be
the most beneficial based on the use case.</p>
<h3 id="module-supervisor-and-genservers" class="section-heading">
  <a href="#module-supervisor-and-genservers" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
  Supervisor and GenServers
</h3>

<p>One alternative to GenEvent is a very minimal solution consisting of using a
supervisor and multiple GenServers started under it. The supervisor acts as
the “event manager” and the children GenServers act as the “event handlers”.
This approach has some shortcomings (it provides no backpressure for example)
but can still replace GenEvent for low-profile usages of it. <a href="http://blog.plataformatec.com.br/2016/11/replacing-genevent-by-a-supervisor-genserver/">This blog post
by José
Valim</a>
has more detailed information on this approach.</p>
<h3 id="module-genstage" class="section-heading">
  <a href="#module-genstage" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
  GenStage
</h3>

<p>If the use case where you were using GenEvent requires more complex logic,
<a href="https://github.com/elixir-lang/gen_stage">GenStage</a> provides a great
alternative. GenStage is an external Elixir library maintained by the Elixir
team; it provides a tool to implement systems that exchange events in a
demand-driven way with built-in support for backpressure. See the <a href="https://hexdocs.pm/gen_stage">GenStage
documentation</a> for more information.</p>
<h3 id="module-gen_event" class="section-heading">
  <a href="#module-gen_event" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
  <code class="inline">:gen_event</code>
</h3>

<p>If your use case requires exactly what GenEvent provided, or you have to
integrate with an existing <code class="inline">:gen_event</code>-based system, you can still use the
<a href="http://erlang.org/doc/man/gen_event.html"><code class="inline">:gen_event</code></a> Erlang module.</p>
        </section>

        <section id="summary" class="details-list">
          <h1 class="section-heading">
            <a class="hover-link" href="#summary">
              <span class="icon-link" aria-hidden="true"></span>
              <span class="sr-only">Link to this section</span>
            </a>
            Summary
          </h1>
  <div class="summary-types summary">
    <h2>
      <a href="#types">Types</a>
    </h2>
<div class="summary-row">
  <div class="summary-signature">
    <a href="#t:handler/0">handler()</a>
  </div>
</div>
<div class="summary-row">
  <div class="summary-signature">
    <a href="#t:manager/0">manager()</a>
  </div>
</div>
<div class="summary-row">
  <div class="summary-signature">
    <a href="#t:name/0">name()</a>
  </div>
</div>
<div class="summary-row">
  <div class="summary-signature">
    <a href="#t:on_start/0">on_start()</a>
  </div>
</div>
<div class="summary-row">
  <div class="summary-signature">
    <a href="#t:options/0">options()</a>
  </div>
</div>
  </div>
          
            <div class="summary-callbacks summary">
    <h2>
      <a href="#callbacks">Callbacks</a>
    </h2>
<div class="summary-row">
  <div class="summary-signature">
    <a href="#c:code_change/3">code_change(old_vsn, state, extra)</a>
  </div>
</div>
<div class="summary-row">
  <div class="summary-signature">
    <a href="#c:handle_call/2">handle_call(request, state)</a>
  </div>
</div>
<div class="summary-row">
  <div class="summary-signature">
    <a href="#c:handle_event/2">handle_event(event, state)</a>
  </div>
</div>
<div class="summary-row">
  <div class="summary-signature">
    <a href="#c:handle_info/2">handle_info(msg, state)</a>
  </div>
</div>
<div class="summary-row">
  <div class="summary-signature">
    <a href="#c:init/1">init(args)</a>
  </div>
</div>
<div class="summary-row">
  <div class="summary-signature">
    <a href="#c:terminate/2">terminate(reason, state)</a>
  </div>
</div>
  </div>

        </section>

        <section id="types" class="details-list">
          <h1 class="section-heading">
            <a class="hover-link" href="#types">
              <span class="icon-link" aria-hidden="true"></span>
              <span class="sr-only">Link to this section</span>
            </a>
            Types
          </h1>
          <div class="types-list">
<div class="detail" id="t:handler/0">
    <div class="detail-header">
    <a href="#t:handler/0" class="detail-link" title="Link to this type">
      <span class="icon-link" aria-hidden="true"></span>
      <span class="sr-only">Link to this type</span>
    </a>
    <span class="signature">handler()</span>
      <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/elixir/lib/gen_event.ex#L86" class="view-source" rel="help" title="View Source">
       <span class="icon-code" aria-hidden="true"></span>
       <span class="sr-only">View Source</span>
     </a>
        
      <div class="specs">
          <pre>handler() :: <a href="typespecs.html#basic-types">atom</a>() | {<a href="typespecs.html#basic-types">atom</a>(), <a href="typespecs.html#built-in-types">term</a>()}</pre>
      </div>
  </div>
  <section class="docstring">
  </section>
</div>
<div class="detail" id="t:manager/0">
    <div class="detail-header">
    <a href="#t:manager/0" class="detail-link" title="Link to this type">
      <span class="icon-link" aria-hidden="true"></span>
      <span class="sr-only">Link to this type</span>
    </a>
    <span class="signature">manager()</span>
      <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/elixir/lib/gen_event.ex#L84" class="view-source" rel="help" title="View Source">
       <span class="icon-code" aria-hidden="true"></span>
       <span class="sr-only">View Source</span>
     </a>
        
      <div class="specs">
          <pre>manager() :: <a href="typespecs.html#basic-types">pid</a>() | <a href="#t:name/0">name</a>() | {<a href="typespecs.html#basic-types">atom</a>(), <a href="typespecs.html#built-in-types">node</a>()}</pre>
      </div>
  </div>
  <section class="docstring">
  </section>
</div>
<div class="detail" id="t:name/0">
    <div class="detail-header">
    <a href="#t:name/0" class="detail-link" title="Link to this type">
      <span class="icon-link" aria-hidden="true"></span>
      <span class="sr-only">Link to this type</span>
    </a>
    <span class="signature">name()</span>
      <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/elixir/lib/gen_event.ex#L80" class="view-source" rel="help" title="View Source">
       <span class="icon-code" aria-hidden="true"></span>
       <span class="sr-only">View Source</span>
     </a>
        
      <div class="specs">
          <pre>name() :: <a href="typespecs.html#basic-types">atom</a>() | {:global, <a href="typespecs.html#built-in-types">term</a>()} | {:via, <a href="typespecs.html#built-in-types">module</a>(), <a href="typespecs.html#built-in-types">term</a>()}</pre>
      </div>
  </div>
  <section class="docstring">
  </section>
</div>
<div class="detail" id="t:on_start/0">
    <div class="detail-header">
    <a href="#t:on_start/0" class="detail-link" title="Link to this type">
      <span class="icon-link" aria-hidden="true"></span>
      <span class="sr-only">Link to this type</span>
    </a>
    <span class="signature">on_start()</span>
      <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/elixir/lib/gen_event.ex#L78" class="view-source" rel="help" title="View Source">
       <span class="icon-code" aria-hidden="true"></span>
       <span class="sr-only">View Source</span>
     </a>
        
      <div class="specs">
          <pre>on_start() :: {:ok, <a href="typespecs.html#basic-types">pid</a>()} | {:error, {:already_started, <a href="typespecs.html#basic-types">pid</a>()}}</pre>
      </div>
  </div>
  <section class="docstring">
  </section>
</div>
<div class="detail" id="t:options/0">
    <div class="detail-header">
    <a href="#t:options/0" class="detail-link" title="Link to this type">
      <span class="icon-link" aria-hidden="true"></span>
      <span class="sr-only">Link to this type</span>
    </a>
    <span class="signature">options()</span>
      <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/elixir/lib/gen_event.ex#L82" class="view-source" rel="help" title="View Source">
       <span class="icon-code" aria-hidden="true"></span>
       <span class="sr-only">View Source</span>
     </a>
        
      <div class="specs">
          <pre>options() :: [{:name, <a href="#t:name/0">name</a>()}]</pre>
      </div>
  </div>
  <section class="docstring">
  </section>
</div>
          </div>
        </section>



        <section id="callbacks" class="details-list">
          <h1 class="section-heading">
            <a class="hover-link" href="#callbacks">
              <span class="icon-link" aria-hidden="true"></span>
              <span class="sr-only">Link to this section</span>
            </a>
            Callbacks
          </h1>
<div class="detail" id="c:code_change/3">
    <div class="detail-header">
    <a href="#c:code_change/3" class="detail-link" title="Link to this callback">
      <span class="icon-link" aria-hidden="true"></span>
      <span class="sr-only">Link to this callback</span>
    </a>
    <span class="signature">code_change(old_vsn, state, extra)</span>
      <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/elixir/lib/gen_event.ex#L75" class="view-source" rel="help" title="View Source">
       <span class="icon-code" aria-hidden="true"></span>
       <span class="sr-only">View Source</span>
     </a>
        
      <div class="specs">
          <pre>code_change(old_vsn, state :: <a href="typespecs.html#built-in-types">term</a>(), extra :: <a href="typespecs.html#built-in-types">term</a>()) ::
  {:ok, new_state :: <a href="typespecs.html#built-in-types">term</a>()}
when old_vsn: <a href="typespecs.html#built-in-types">term</a>() | {:down, <a href="typespecs.html#built-in-types">term</a>()}</pre>
      </div>
  </div>
  <section class="docstring">
  </section>
</div>
<div class="detail" id="c:handle_call/2">
    <div class="detail-header">
    <a href="#c:handle_call/2" class="detail-link" title="Link to this callback">
      <span class="icon-link" aria-hidden="true"></span>
      <span class="sr-only">Link to this callback</span>
    </a>
    <span class="signature">handle_call(request, state)</span>
      <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/elixir/lib/gen_event.ex#L60" class="view-source" rel="help" title="View Source">
       <span class="icon-code" aria-hidden="true"></span>
       <span class="sr-only">View Source</span>
     </a>
        
      <div class="specs">
          <pre>handle_call(request :: <a href="typespecs.html#built-in-types">term</a>(), state :: <a href="typespecs.html#built-in-types">term</a>()) ::
  {:ok, reply, new_state}
  | {:ok, reply, new_state, :hibernate}
  | {:remove_handler, reply}
when reply: <a href="typespecs.html#built-in-types">term</a>(), new_state: <a href="typespecs.html#built-in-types">term</a>()</pre>
      </div>
  </div>
  <section class="docstring">
  </section>
</div>
<div class="detail" id="c:handle_event/2">
    <div class="detail-header">
    <a href="#c:handle_event/2" class="detail-link" title="Link to this callback">
      <span class="icon-link" aria-hidden="true"></span>
      <span class="sr-only">Link to this callback</span>
    </a>
    <span class="signature">handle_event(event, state)</span>
      <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/elixir/lib/gen_event.ex#L54" class="view-source" rel="help" title="View Source">
       <span class="icon-code" aria-hidden="true"></span>
       <span class="sr-only">View Source</span>
     </a>
        
      <div class="specs">
          <pre>handle_event(event :: <a href="typespecs.html#built-in-types">term</a>(), state :: <a href="typespecs.html#built-in-types">term</a>()) ::
  {:ok, new_state} | {:ok, new_state, :hibernate} | :remove_handler
when new_state: <a href="typespecs.html#built-in-types">term</a>()</pre>
      </div>
  </div>
  <section class="docstring">
  </section>
</div>
<div class="detail" id="c:handle_info/2">
    <div class="detail-header">
    <a href="#c:handle_info/2" class="detail-link" title="Link to this callback">
      <span class="icon-link" aria-hidden="true"></span>
      <span class="sr-only">Link to this callback</span>
    </a>
    <span class="signature">handle_info(msg, state)</span>
      <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/elixir/lib/gen_event.ex#L66" class="view-source" rel="help" title="View Source">
       <span class="icon-code" aria-hidden="true"></span>
       <span class="sr-only">View Source</span>
     </a>
        
      <div class="specs">
          <pre>handle_info(msg :: <a href="typespecs.html#built-in-types">term</a>(), state :: <a href="typespecs.html#built-in-types">term</a>()) ::
  {:ok, new_state} | {:ok, new_state, :hibernate} | :remove_handler
when new_state: <a href="typespecs.html#built-in-types">term</a>()</pre>
      </div>
  </div>
  <section class="docstring">
  </section>
</div>
<div class="detail" id="c:init/1">
    <div class="detail-header">
    <a href="#c:init/1" class="detail-link" title="Link to this callback">
      <span class="icon-link" aria-hidden="true"></span>
      <span class="sr-only">Link to this callback</span>
    </a>
    <span class="signature">init(args)</span>
      <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/elixir/lib/gen_event.ex#L48" class="view-source" rel="help" title="View Source">
       <span class="icon-code" aria-hidden="true"></span>
       <span class="sr-only">View Source</span>
     </a>
        
      <div class="specs">
          <pre>init(args :: <a href="typespecs.html#built-in-types">term</a>()) ::
  {:ok, state} | {:ok, state, :hibernate} | {:error, reason :: <a href="typespecs.html#basic-types">any</a>()}
when state: <a href="typespecs.html#basic-types">any</a>()</pre>
      </div>
  </div>
  <section class="docstring">
  </section>
</div>
<div class="detail" id="c:terminate/2">
    <div class="detail-header">
    <a href="#c:terminate/2" class="detail-link" title="Link to this callback">
      <span class="icon-link" aria-hidden="true"></span>
      <span class="sr-only">Link to this callback</span>
    </a>
    <span class="signature">terminate(reason, state)</span>
      <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/elixir/lib/gen_event.ex#L72" class="view-source" rel="help" title="View Source">
       <span class="icon-code" aria-hidden="true"></span>
       <span class="sr-only">View Source</span>
     </a>
        
      <div class="specs">
          <pre>terminate(reason, state :: <a href="typespecs.html#built-in-types">term</a>()) :: <a href="typespecs.html#built-in-types">term</a>()
when reason:
       :stop | {:stop, <a href="typespecs.html#built-in-types">term</a>()} | :remove_handler | {:error, <a href="typespecs.html#built-in-types">term</a>()} | <a href="typespecs.html#built-in-types">term</a>()</pre>
      </div>
  </div>
  <section class="docstring">
  </section>
</div>
        </section>
          <footer class="footer">
        <p>
          <span class="line">
            Built using
            <a href="https://github.com/elixir-lang/ex_doc" title="ExDoc" target="_blank" rel="help noopener">ExDoc</a> (v0.19.1),
          </span>
          <span class="line">
            designed by
            <a href="https://twitter.com/dignifiedquire" target="_blank" rel="noopener" title="@dignifiedquire">Friedel Ziegelmayer</a>.
            </span>
        </p>
      </footer>
    </div>
  </div>
</section>
</div>
  <script src="dist/app-a0c90688fa.js"></script>
  
  </body>
</html>