Sophie

Sophie

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

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>Task.Supervisor – Elixir v1.7.2</title>
    <link rel="stylesheet" href="dist/app-240d7fc7e5.css" />
      <link rel="canonical" href="https://hexdocs.pm/elixir/v1.7/Task.Supervisor.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>
Task.Supervisor        
          <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/elixir/lib/task/supervisor.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>


        <section id="moduledoc">
<p>A task supervisor.</p>
<p>This module defines a supervisor which can be used to dynamically
supervise tasks.</p>
<p>A task supervisor is started with no children, often under a
supervisor and a name:</p>
<pre><code class="nohighlight makeup elixir"><span class="n">children</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p" data-group-id="3155626134-1">[</span><span class="w">
  </span><span class="p" data-group-id="3155626134-2">{</span><span class="nc">Task.Supervisor</span><span class="p">,</span><span class="w"> </span><span class="ss">name</span><span class="p">:</span><span class="w"> </span><span class="nc">MyApp.TaskSupervisor</span><span class="p" data-group-id="3155626134-2">}</span><span class="w">
</span><span class="p" data-group-id="3155626134-1">]</span><span class="w">

</span><span class="nc">Supervisor</span><span class="o">.</span><span class="n">start_link</span><span class="p" data-group-id="3155626134-3">(</span><span class="n">children</span><span class="p">,</span><span class="w"> </span><span class="ss">strategy</span><span class="p">:</span><span class="w"> </span><span class="ss">:one_for_one</span><span class="p" data-group-id="3155626134-3">)</span></code></pre>
<p>The options given in the child specification are documented in <a href="#start_link/1"><code class="inline">start_link/1</code></a>.</p>
<p>See the <a href="Task.html"><code class="inline">Task</code></a> module for more examples.</p>
<h2 id="module-name-registration" class="section-heading">
  <a href="#module-name-registration" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
  Name registration
</h2>

<p>A <a href="Task.Supervisor.html#content"><code class="inline">Task.Supervisor</code></a> is bound to the same name registration rules as a
<a href="GenServer.html"><code class="inline">GenServer</code></a>. Read more about them in the <a href="GenServer.html"><code class="inline">GenServer</code></a> docs.</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:option/0">option()</a>
  </div>
    <div class="summary-synopsis"><p>Option values used by <code class="inline">start_link</code></p>
</div>
</div>
  </div>
          
  <div class="summary-functions summary">
    <h2>
      <a href="#functions">Functions</a>
    </h2>
<div class="summary-row">
  <div class="summary-signature">
    <a href="#async/3">async(supervisor, fun, options \\ [])</a>
  </div>
    <div class="summary-synopsis"><p>Starts a task that can be awaited on</p>
</div>
</div>
<div class="summary-row">
  <div class="summary-signature">
    <a href="#async/5">async(supervisor, module, fun, args, options \\ [])</a>
  </div>
    <div class="summary-synopsis"><p>Starts a task that can be awaited on</p>
</div>
</div>
<div class="summary-row">
  <div class="summary-signature">
    <a href="#async_nolink/3">async_nolink(supervisor, fun, options \\ [])</a>
  </div>
    <div class="summary-synopsis"><p>Starts a task that can be awaited on</p>
</div>
</div>
<div class="summary-row">
  <div class="summary-signature">
    <a href="#async_nolink/5">async_nolink(supervisor, module, fun, args, options \\ [])</a>
  </div>
    <div class="summary-synopsis"><p>Starts a task that can be awaited on</p>
</div>
</div>
<div class="summary-row">
  <div class="summary-signature">
    <a href="#async_stream/4">async_stream(supervisor, enumerable, fun, options \\ [])</a>
  </div>
    <div class="summary-synopsis"><p>Returns a stream that runs the given function <code class="inline">fun</code> concurrently
on each item in <code class="inline">enumerable</code></p>
</div>
</div>
<div class="summary-row">
  <div class="summary-signature">
    <a href="#async_stream/6">async_stream(supervisor, enumerable, module, function, args, options \\ [])</a>
  </div>
    <div class="summary-synopsis"><p>Returns a stream that runs the given <code class="inline">module</code>, <code class="inline">function</code>, and <code class="inline">args</code>
concurrently on each item in <code class="inline">enumerable</code></p>
</div>
</div>
<div class="summary-row">
  <div class="summary-signature">
    <a href="#async_stream_nolink/4">async_stream_nolink(supervisor, enumerable, fun, options \\ [])</a>
  </div>
    <div class="summary-synopsis"><p>Returns a stream that runs the given <code class="inline">function</code> concurrently on each
item in <code class="inline">enumerable</code></p>
</div>
</div>
<div class="summary-row">
  <div class="summary-signature">
    <a href="#async_stream_nolink/6">async_stream_nolink(supervisor, enumerable, module, function, args, options \\ [])</a>
  </div>
    <div class="summary-synopsis"><p>Returns a stream that runs the given <code class="inline">module</code>, <code class="inline">function</code>, and <code class="inline">args</code>
concurrently on each item in <code class="inline">enumerable</code></p>
</div>
</div>
<div class="summary-row">
  <div class="summary-signature">
    <a href="#children/1">children(supervisor)</a>
  </div>
    <div class="summary-synopsis"><p>Returns all children PIDs</p>
</div>
</div>
<div class="summary-row">
  <div class="summary-signature">
    <a href="#start_child/3">start_child(supervisor, fun, options \\ [])</a>
  </div>
    <div class="summary-synopsis"><p>Starts a task as a child of the given <code class="inline">supervisor</code></p>
</div>
</div>
<div class="summary-row">
  <div class="summary-signature">
    <a href="#start_child/5">start_child(supervisor, module, fun, args, options \\ [])</a>
  </div>
    <div class="summary-synopsis"><p>Starts a task as a child of the given <code class="inline">supervisor</code></p>
</div>
</div>
<div class="summary-row">
  <div class="summary-signature">
    <a href="#start_link/1">start_link(options \\ [])</a>
  </div>
    <div class="summary-synopsis"><p>Starts a new supervisor</p>
</div>
</div>
<div class="summary-row">
  <div class="summary-signature">
    <a href="#terminate_child/2">terminate_child(supervisor, pid)</a>
  </div>
    <div class="summary-synopsis"><p>Terminates the child with the given <code class="inline">pid</code></p>
</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:option/0">
    <div class="detail-header">
    <a href="#t:option/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">option()</span>
      <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/elixir/lib/task/supervisor.ex#L28" 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>option() ::
  <a href="Supervisor.html#t:option/0">Supervisor.option</a>()
  | {:restart, <a href="http://www.erlang.org/doc/man/supervisor.html#type-restart">:supervisor.restart</a>()}
  | {:shutdown, <a href="http://www.erlang.org/doc/man/supervisor.html#type-shutdown">:supervisor.shutdown</a>()}</pre>
      </div>
  </div>
  <section class="docstring">
<p>Option values used by <code class="inline">start_link</code></p>
  </section>
</div>
          </div>
        </section>


        <section id="functions" class="details-list">
          <h1 class="section-heading">
            <a class="hover-link" href="#functions">
              <span class="icon-link" aria-hidden="true"></span>
              <span class="sr-only">Link to this section</span>
            </a>
            Functions
          </h1>
<div class="detail" id="async/3">
  
    <span id="async/2"></span>
  <div class="detail-header">
    <a href="#async/3" class="detail-link" title="Link to this function">
      <span class="icon-link" aria-hidden="true"></span>
      <span class="sr-only">Link to this function</span>
    </a>
    <span class="signature">async(supervisor, fun, options \\ [])</span>
      <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/elixir/lib/task/supervisor.ex#L111" 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>async(<a href="Supervisor.html#t:supervisor/0">Supervisor.supervisor</a>(), (() -> <a href="typespecs.html#basic-types">any</a>()), <a href="Keyword.html#t:t/0">Keyword.t</a>()) :: <a href="Task.html#t:t/0">Task.t</a>()</pre>
      </div>
  </div>
  <section class="docstring">
<p>Starts a task that can be awaited on.</p>
<p>The <code class="inline">supervisor</code> must be a reference as defined in <a href="Task.Supervisor.html#content"><code class="inline">Task.Supervisor</code></a>.
The task will still be linked to the caller, see <a href="Task.html#async/3"><code class="inline">Task.async/3</code></a> for
more information and <a href="#async_nolink/2"><code class="inline">async_nolink/2</code></a> for a non-linked variant.</p>
<h2 id="async/3-options" class="section-heading">
  <a href="#async/3-options" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
  Options
</h2>

<ul>
<li><code class="inline">:shutdown</code> - <code class="inline">:brutal_kill</code> if the tasks must be killed directly on shutdown
or an integer indicating the timeout value, defaults to 5000 milliseconds.
</li>
</ul>
  </section>
</div>
<div class="detail" id="async/5">
  
    <span id="async/4"></span>
  <div class="detail-header">
    <a href="#async/5" class="detail-link" title="Link to this function">
      <span class="icon-link" aria-hidden="true"></span>
      <span class="sr-only">Link to this function</span>
    </a>
    <span class="signature">async(supervisor, module, fun, args, options \\ [])</span>
      <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/elixir/lib/task/supervisor.ex#L129" 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>async(<a href="Supervisor.html#t:supervisor/0">Supervisor.supervisor</a>(), <a href="typespecs.html#built-in-types">module</a>(), <a href="typespecs.html#basic-types">atom</a>(), [<a href="typespecs.html#built-in-types">term</a>()], <a href="Keyword.html#t:t/0">Keyword.t</a>()) ::
  <a href="Task.html#t:t/0">Task.t</a>()</pre>
      </div>
  </div>
  <section class="docstring">
<p>Starts a task that can be awaited on.</p>
<p>The <code class="inline">supervisor</code> must be a reference as defined in <a href="Task.Supervisor.html#content"><code class="inline">Task.Supervisor</code></a>.
The task will still be linked to the caller, see <a href="Task.html#async/3"><code class="inline">Task.async/3</code></a> for
more information and <a href="#async_nolink/2"><code class="inline">async_nolink/2</code></a> for a non-linked variant.</p>
<h2 id="async/5-options" class="section-heading">
  <a href="#async/5-options" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
  Options
</h2>

<ul>
<li><code class="inline">:shutdown</code> - <code class="inline">:brutal_kill</code> if the tasks must be killed directly on shutdown
or an integer indicating the timeout value, defaults to 5000 milliseconds.
</li>
</ul>
  </section>
</div>
<div class="detail" id="async_nolink/3">
  
    <span id="async_nolink/2"></span>
  <div class="detail-header">
    <a href="#async_nolink/3" class="detail-link" title="Link to this function">
      <span class="icon-link" aria-hidden="true"></span>
      <span class="sr-only">Link to this function</span>
    </a>
    <span class="signature">async_nolink(supervisor, fun, options \\ [])</span>
      <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/elixir/lib/task/supervisor.ex#L161" 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>async_nolink(<a href="Supervisor.html#t:supervisor/0">Supervisor.supervisor</a>(), (() -> <a href="typespecs.html#basic-types">any</a>()), <a href="Keyword.html#t:t/0">Keyword.t</a>()) :: <a href="Task.html#t:t/0">Task.t</a>()</pre>
      </div>
  </div>
  <section class="docstring">
<p>Starts a task that can be awaited on.</p>
<p>The <code class="inline">supervisor</code> must be a reference as defined in <a href="Task.Supervisor.html#content"><code class="inline">Task.Supervisor</code></a>.
The task won’t be linked to the caller, see <a href="Task.html#async/3"><code class="inline">Task.async/3</code></a> for
more information.</p>
<h2 id="async_nolink/3-options" class="section-heading">
  <a href="#async_nolink/3-options" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
  Options
</h2>

<ul>
<li><code class="inline">:shutdown</code> - <code class="inline">:brutal_kill</code> if the tasks must be killed directly on shutdown
or an integer indicating the timeout value, defaults to 5000 milliseconds.
</li>
</ul>
<h2 id="async_nolink/3-compatibility-with-otp-behaviours" class="section-heading">
  <a href="#async_nolink/3-compatibility-with-otp-behaviours" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
  Compatibility with OTP behaviours
</h2>

<p>If you create a task using <code class="inline">async_nolink</code> inside an OTP behaviour
like <a href="GenServer.html"><code class="inline">GenServer</code></a>, you should match on the message coming from the
task inside your <a href="GenServer.html#c:handle_info/2"><code class="inline">GenServer.handle_info/2</code></a> callback.</p>
<p>The reply sent by the task will be in the format <code class="inline">{ref, result}</code>,
where <code class="inline">ref</code> is the monitor reference held by the task struct
and <code class="inline">result</code> is the return value of the task function.</p>
<p>Keep in mind that, regardless of how the task created with <code class="inline">async_nolink</code>
terminates, the caller’s process will always receive a <code class="inline">:DOWN</code> message
with the same <code class="inline">ref</code> value that is held by the task struct. If the task
terminates normally, the reason in the <code class="inline">:DOWN</code> message will be <code class="inline">:normal</code>.</p>
  </section>
</div>
<div class="detail" id="async_nolink/5">
  
    <span id="async_nolink/4"></span>
  <div class="detail-header">
    <a href="#async_nolink/5" class="detail-link" title="Link to this function">
      <span class="icon-link" aria-hidden="true"></span>
      <span class="sr-only">Link to this function</span>
    </a>
    <span class="signature">async_nolink(supervisor, module, fun, args, options \\ [])</span>
      <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/elixir/lib/task/supervisor.ex#L177" 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>async_nolink(<a href="Supervisor.html#t:supervisor/0">Supervisor.supervisor</a>(), <a href="typespecs.html#built-in-types">module</a>(), <a href="typespecs.html#basic-types">atom</a>(), [<a href="typespecs.html#built-in-types">term</a>()], <a href="Keyword.html#t:t/0">Keyword.t</a>()) ::
  <a href="Task.html#t:t/0">Task.t</a>()</pre>
      </div>
  </div>
  <section class="docstring">
<p>Starts a task that can be awaited on.</p>
<p>The <code class="inline">supervisor</code> must be a reference as defined in <a href="Task.Supervisor.html#content"><code class="inline">Task.Supervisor</code></a>.
The task won’t be linked to the caller, see <a href="Task.html#async/3"><code class="inline">Task.async/3</code></a> for
more information.</p>
<p>Note this function requires the task supervisor to have <code class="inline">:temporary</code>
as the <code class="inline">:restart</code> option (the default), as <a href="#async_nolink/4"><code class="inline">async_nolink/4</code></a> keeps a
direct reference to the task which is lost if the task is restarted.</p>
  </section>
</div>
<div class="detail" id="async_stream/4">
  
    <span id="async_stream/3"></span>
  <div class="detail-header">
    <a href="#async_stream/4" class="detail-link" title="Link to this function">
      <span class="icon-link" aria-hidden="true"></span>
      <span class="sr-only">Link to this function</span>
    </a>
    <span class="signature">async_stream(supervisor, enumerable, fun, options \\ [])</span>
      <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/elixir/lib/task/supervisor.ex#L250" class="view-source" rel="help" title="View Source">
       <span class="icon-code" aria-hidden="true"></span>
       <span class="sr-only">View Source</span>
     </a>
    
      <span class="note">(since 1.4.0)</span>
    
      <div class="specs">
          <pre>async_stream(
  <a href="Supervisor.html#t:supervisor/0">Supervisor.supervisor</a>(),
  <a href="Enumerable.html#t:t/0">Enumerable.t</a>(),
  (<a href="typespecs.html#built-in-types">term</a>() -> <a href="typespecs.html#built-in-types">term</a>()),
  <a href="typespecs.html#built-in-types">keyword</a>()
) :: <a href="Enumerable.html#t:t/0">Enumerable.t</a>()</pre>
      </div>
  </div>
  <section class="docstring">
<p>Returns a stream that runs the given function <code class="inline">fun</code> concurrently
on each item in <code class="inline">enumerable</code>.</p>
<p>Each item in <code class="inline">enumerable</code> is passed as argument to the given function <code class="inline">fun</code>
and processed by its own task. The tasks will be spawned under the given
<code class="inline">supervisor</code> and linked to the current process, similarly to <a href="#async/2"><code class="inline">async/2</code></a>.</p>
<p>See <a href="#async_stream/6"><code class="inline">async_stream/6</code></a> for discussion, options, and examples.</p>
  </section>
</div>
<div class="detail" id="async_stream/6">
  
    <span id="async_stream/5"></span>
  <div class="detail-header">
    <a href="#async_stream/6" class="detail-link" title="Link to this function">
      <span class="icon-link" aria-hidden="true"></span>
      <span class="sr-only">Link to this function</span>
    </a>
    <span class="signature">async_stream(supervisor, enumerable, module, function, args, options \\ [])</span>
      <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/elixir/lib/task/supervisor.ex#L232" class="view-source" rel="help" title="View Source">
       <span class="icon-code" aria-hidden="true"></span>
       <span class="sr-only">View Source</span>
     </a>
    
      <span class="note">(since 1.4.0)</span>
    
      <div class="specs">
          <pre>async_stream(
  <a href="Supervisor.html#t:supervisor/0">Supervisor.supervisor</a>(),
  <a href="Enumerable.html#t:t/0">Enumerable.t</a>(),
  <a href="typespecs.html#built-in-types">module</a>(),
  <a href="typespecs.html#basic-types">atom</a>(),
  [<a href="typespecs.html#built-in-types">term</a>()],
  <a href="typespecs.html#built-in-types">keyword</a>()
) :: <a href="Enumerable.html#t:t/0">Enumerable.t</a>()</pre>
      </div>
  </div>
  <section class="docstring">
<p>Returns a stream that runs the given <code class="inline">module</code>, <code class="inline">function</code>, and <code class="inline">args</code>
concurrently on each item in <code class="inline">enumerable</code>.</p>
<p>Each item will be prepended to the given <code class="inline">args</code> and processed by its
own task. The tasks will be spawned under the given <code class="inline">supervisor</code> and
linked to the current process, similarly to <a href="#async/4"><code class="inline">async/4</code></a>.</p>
<p>When streamed, each task will emit <code class="inline">{:ok, value}</code> upon successful
completion or <code class="inline">{:exit, reason}</code> if the caller is trapping exits.
Results are emitted in the same order as the original <code class="inline">enumerable</code>.</p>
<p>The level of concurrency can be controlled via the <code class="inline">:max_concurrency</code>
option and defaults to <a href="System.html#schedulers_online/0"><code class="inline">System.schedulers_online/0</code></a>. A timeout
can also be given as an option representing the maximum amount of
time to wait without a task reply.</p>
<p>Finally, if you find yourself trapping exits to handle exits inside
the async stream, consider using <a href="#async_stream_nolink/6"><code class="inline">async_stream_nolink/6</code></a> to start tasks
that are not linked to the current process.</p>
<h2 id="async_stream/6-options" class="section-heading">
  <a href="#async_stream/6-options" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
  Options
</h2>

<ul>
<li><code class="inline">:max_concurrency</code> - sets the maximum number of tasks to run
at the same time. Defaults to <a href="System.html#schedulers_online/0"><code class="inline">System.schedulers_online/0</code></a>.
</li>
<li><code class="inline">:ordered</code> - whether the results should be returned in the same order
as the input stream. This option is useful when you have large
streams and don’t want to buffer results before they are delivered.
Defaults to <code class="inline">true</code>.
</li>
<li><code class="inline">:timeout</code> - the maximum amount of time to wait (in milliseconds)
without receiving a task reply (across all running tasks).
Defaults to <code class="inline">5000</code>.
</li>
<li><p><code class="inline">:on_timeout</code> - what do to when a task times out. The possible
values are:</p>
<ul>
<li><code class="inline">:exit</code> (default) - the process that spawned the tasks exits.
</li>
<li><code class="inline">:kill_task</code> - the task that timed out is killed. The value
  emitted for that task is <code class="inline">{:exit, :timeout}</code>.
</li>
</ul>
</li>
<li><code class="inline">:shutdown</code> - <code class="inline">:brutal_kill</code> if the tasks must be killed directly on shutdown
or an integer indicating the timeout value, defaults to 5000 milliseconds.
</li>
</ul>
<h2 id="async_stream/6-examples" class="section-heading">
  <a href="#async_stream/6-examples" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
  Examples
</h2>

<p>Let’s build a stream and then enumerate it:</p>
<pre><code class="nohighlight makeup elixir"><span class="n">stream</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Task.Supervisor</span><span class="o">.</span><span class="n">async_stream</span><span class="p" data-group-id="3147713372-1">(</span><span class="nc">MySupervisor</span><span class="p">,</span><span class="w"> </span><span class="n">collection</span><span class="p">,</span><span class="w"> </span><span class="nc">Mod</span><span class="p">,</span><span class="w"> </span><span class="ss">:expensive_fun</span><span class="p">,</span><span class="w"> </span><span class="p" data-group-id="3147713372-2">[</span><span class="p" data-group-id="3147713372-2">]</span><span class="p" data-group-id="3147713372-1">)</span><span class="w">
</span><span class="nc">Enum</span><span class="o">.</span><span class="n">to_list</span><span class="p" data-group-id="3147713372-3">(</span><span class="n">stream</span><span class="p" data-group-id="3147713372-3">)</span></code></pre>
  </section>
</div>
<div class="detail" id="async_stream_nolink/4">
  
    <span id="async_stream_nolink/3"></span>
  <div class="detail-header">
    <a href="#async_stream_nolink/4" class="detail-link" title="Link to this function">
      <span class="icon-link" aria-hidden="true"></span>
      <span class="sr-only">Link to this function</span>
    </a>
    <span class="signature">async_stream_nolink(supervisor, enumerable, fun, options \\ [])</span>
      <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/elixir/lib/task/supervisor.ex#L291" class="view-source" rel="help" title="View Source">
       <span class="icon-code" aria-hidden="true"></span>
       <span class="sr-only">View Source</span>
     </a>
    
      <span class="note">(since 1.4.0)</span>
    
      <div class="specs">
          <pre>async_stream_nolink(
  <a href="Supervisor.html#t:supervisor/0">Supervisor.supervisor</a>(),
  <a href="Enumerable.html#t:t/0">Enumerable.t</a>(),
  (<a href="typespecs.html#built-in-types">term</a>() -> <a href="typespecs.html#built-in-types">term</a>()),
  <a href="typespecs.html#built-in-types">keyword</a>()
) :: <a href="Enumerable.html#t:t/0">Enumerable.t</a>()</pre>
      </div>
  </div>
  <section class="docstring">
<p>Returns a stream that runs the given <code class="inline">function</code> concurrently on each
item in <code class="inline">enumerable</code>.</p>
<p>Each item in <code class="inline">enumerable</code> is passed as argument to the given function <code class="inline">fun</code>
and processed by its own task. The tasks will be spawned under the given
<code class="inline">supervisor</code> and will not be linked to the current process, similarly to <a href="#async_nolink/2"><code class="inline">async_nolink/2</code></a>.</p>
<p>See <a href="#async_stream/6"><code class="inline">async_stream/6</code></a> for discussion and examples.</p>
  </section>
</div>
<div class="detail" id="async_stream_nolink/6">
  
    <span id="async_stream_nolink/5"></span>
  <div class="detail-header">
    <a href="#async_stream_nolink/6" class="detail-link" title="Link to this function">
      <span class="icon-link" aria-hidden="true"></span>
      <span class="sr-only">Link to this function</span>
    </a>
    <span class="signature">async_stream_nolink(supervisor, enumerable, module, function, args, options \\ [])</span>
      <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/elixir/lib/task/supervisor.ex#L273" class="view-source" rel="help" title="View Source">
       <span class="icon-code" aria-hidden="true"></span>
       <span class="sr-only">View Source</span>
     </a>
    
      <span class="note">(since 1.4.0)</span>
    
      <div class="specs">
          <pre>async_stream_nolink(
  <a href="Supervisor.html#t:supervisor/0">Supervisor.supervisor</a>(),
  <a href="Enumerable.html#t:t/0">Enumerable.t</a>(),
  <a href="typespecs.html#built-in-types">module</a>(),
  <a href="typespecs.html#basic-types">atom</a>(),
  [<a href="typespecs.html#built-in-types">term</a>()],
  <a href="typespecs.html#built-in-types">keyword</a>()
) :: <a href="Enumerable.html#t:t/0">Enumerable.t</a>()</pre>
      </div>
  </div>
  <section class="docstring">
<p>Returns a stream that runs the given <code class="inline">module</code>, <code class="inline">function</code>, and <code class="inline">args</code>
concurrently on each item in <code class="inline">enumerable</code>.</p>
<p>Each item in <code class="inline">enumerable</code> will be prepended to the given <code class="inline">args</code> and processed
by its own task. The tasks will be spawned under the given <code class="inline">supervisor</code> and
will not be linked to the current process, similarly to <a href="#async_nolink/4"><code class="inline">async_nolink/4</code></a>.</p>
<p>See <a href="#async_stream/6"><code class="inline">async_stream/6</code></a> for discussion, options, and examples.</p>
  </section>
</div>
<div class="detail" id="children/1">
    <div class="detail-header">
    <a href="#children/1" class="detail-link" title="Link to this function">
      <span class="icon-link" aria-hidden="true"></span>
      <span class="sr-only">Link to this function</span>
    </a>
    <span class="signature">children(supervisor)</span>
      <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/elixir/lib/task/supervisor.ex#L307" 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>children(<a href="Supervisor.html#t:supervisor/0">Supervisor.supervisor</a>()) :: [<a href="typespecs.html#basic-types">pid</a>()]</pre>
      </div>
  </div>
  <section class="docstring">
<p>Returns all children PIDs.</p>
  </section>
</div>
<div class="detail" id="start_child/3">
  
    <span id="start_child/2"></span>
  <div class="detail-header">
    <a href="#start_child/3" class="detail-link" title="Link to this function">
      <span class="icon-link" aria-hidden="true"></span>
      <span class="sr-only">Link to this function</span>
    </a>
    <span class="signature">start_child(supervisor, fun, options \\ [])</span>
      <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/elixir/lib/task/supervisor.ex#L333" 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>start_child(<a href="Supervisor.html#t:supervisor/0">Supervisor.supervisor</a>(), (() -> <a href="typespecs.html#basic-types">any</a>()), <a href="typespecs.html#built-in-types">keyword</a>()) ::
  <a href="DynamicSupervisor.html#t:on_start_child/0">DynamicSupervisor.on_start_child</a>()</pre>
      </div>
  </div>
  <section class="docstring">
<p>Starts a task as a child of the given <code class="inline">supervisor</code>.</p>
<p>Note that the spawned process is not linked to the caller, but
only to the supervisor. This command is useful in case the
task needs to perform side-effects (like I/O) and does not need
to report back to the caller.</p>
<h2 id="start_child/3-options" class="section-heading">
  <a href="#start_child/3-options" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
  Options
</h2>

<ul>
<li><p><code class="inline">:restart</code> - the restart strategy, may be <code class="inline">:temporary</code> (the default),
<code class="inline">:transient</code> or <code class="inline">:permanent</code>. <code class="inline">:temporary</code> means the task is never
restarted, <code class="inline">:transient</code> means it is restarted if the exit is not
<code class="inline">:normal</code>, <code class="inline">:shutdown</code> or <code class="inline">{:shutdown, reason}</code>. A <code class="inline">:permanent</code> restart
strategy means it is always restarted. It defaults to <code class="inline">:temporary</code>.</p>
</li>
<li><p><code class="inline">:shutdown</code> - <code class="inline">:brutal_kill</code> if the tasks must be killed directly on shutdown
or an integer indicating the timeout value, defaults to 5000 milliseconds.</p>
</li>
</ul>
  </section>
</div>
<div class="detail" id="start_child/5">
  
    <span id="start_child/4"></span>
  <div class="detail-header">
    <a href="#start_child/5" class="detail-link" title="Link to this function">
      <span class="icon-link" aria-hidden="true"></span>
      <span class="sr-only">Link to this function</span>
    </a>
    <span class="signature">start_child(supervisor, module, fun, args, options \\ [])</span>
      <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/elixir/lib/task/supervisor.ex#L348" 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>start_child(<a href="Supervisor.html#t:supervisor/0">Supervisor.supervisor</a>(), <a href="typespecs.html#built-in-types">module</a>(), <a href="typespecs.html#basic-types">atom</a>(), [<a href="typespecs.html#built-in-types">term</a>()], <a href="typespecs.html#built-in-types">keyword</a>()) ::
  <a href="DynamicSupervisor.html#t:on_start_child/0">DynamicSupervisor.on_start_child</a>()</pre>
      </div>
  </div>
  <section class="docstring">
<p>Starts a task as a child of the given <code class="inline">supervisor</code>.</p>
<p>Similar to <a href="#start_child/2"><code class="inline">start_child/2</code></a> except the task is specified
by the given <code class="inline">module</code>, <code class="inline">fun</code> and <code class="inline">args</code>.</p>
  </section>
</div>
<div class="detail" id="start_link/1">
  
    <span id="start_link/0"></span>
  <div class="detail-header">
    <a href="#start_link/1" class="detail-link" title="Link to this function">
      <span class="icon-link" aria-hidden="true"></span>
      <span class="sr-only">Link to this function</span>
    </a>
    <span class="signature">start_link(options \\ [])</span>
      <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/elixir/lib/task/supervisor.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>start_link([<a href="#t:option/0">option</a>()]) :: <a href="Supervisor.html#t:on_start/0">Supervisor.on_start</a>()</pre>
      </div>
  </div>
  <section class="docstring">
<p>Starts a new supervisor.</p>
<h2 id="start_link/1-examples" class="section-heading">
  <a href="#start_link/1-examples" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
  Examples
</h2>

<p>A task supervisor is typically started under a supervision tree using
the tuple format:</p>
<pre><code class="nohighlight makeup elixir"><span class="p" data-group-id="9031282931-1">{</span><span class="nc">Task.Supervisor</span><span class="p">,</span><span class="w"> </span><span class="ss">name</span><span class="p">:</span><span class="w"> </span><span class="nc">MyApp.TaskSupervisor</span><span class="p" data-group-id="9031282931-1">}</span></code></pre>
<p>You can also start it by calling <a href="#start_link/1"><code class="inline">start_link/1</code></a> directly:</p>
<pre><code class="nohighlight makeup elixir"><span class="nc">Task.Supervisor</span><span class="o">.</span><span class="n">start_link</span><span class="p" data-group-id="3167527383-1">(</span><span class="ss">name</span><span class="p">:</span><span class="w"> </span><span class="nc">MyApp.TaskSupervisor</span><span class="p" data-group-id="3167527383-1">)</span></code></pre>
<p>But this is recommended only for scripting and should be avoided in
production code. Generally speaking, processes should always be started
inside supervision trees.</p>
<h2 id="start_link/1-options" class="section-heading">
  <a href="#start_link/1-options" class="hover-link"><span class="icon-link" aria-hidden="true"></span></a>
  Options
</h2>

<ul>
<li><p><code class="inline">:name</code> - used to register a supervisor name, the supported values are
described under the <code class="inline">Name Registration</code> section in the <a href="GenServer.html"><code class="inline">GenServer</code></a> module
docs;</p>
</li>
<li><p><code class="inline">:max_restarts</code>, <code class="inline">:max_seconds</code> and <code class="inline">:max_children</code> - as specified in
<a href="DynamicSupervisor.html"><code class="inline">DynamicSupervisor</code></a>;</p>
</li>
</ul>
<p>This function could also receive <code class="inline">:restart</code> and <code class="inline">:shutdown</code> as options
but those two options have been deprecated and it is now preferred to
give them directly to <code class="inline">start_child</code> and <code class="inline">async</code>.</p>
  </section>
</div>
<div class="detail" id="terminate_child/2">
    <div class="detail-header">
    <a href="#terminate_child/2" class="detail-link" title="Link to this function">
      <span class="icon-link" aria-hidden="true"></span>
      <span class="sr-only">Link to this function</span>
    </a>
    <span class="signature">terminate_child(supervisor, pid)</span>
      <a href="https://github.com/elixir-lang/elixir/blob/v1.7.2/lib/elixir/lib/task/supervisor.ex#L299" 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_child(<a href="Supervisor.html#t:supervisor/0">Supervisor.supervisor</a>(), <a href="typespecs.html#basic-types">pid</a>()) :: :ok | {:error, :not_found}</pre>
      </div>
  </div>
  <section class="docstring">
<p>Terminates the child with the given <code class="inline">pid</code>.</p>
  </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>