<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="36953" data-post-id="36953">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="peerreynders" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/peerreynders/120/5826_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  peerreynders
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Sometimes it takes some digging to figure out how things work - for example <a href="https://github.com/edgurgel/httpoison" rel="noopener nofollow ugc">HTTPoison</a> is based on <a href="https://github.com/benoitc/hackney" rel="noopener nofollow ugc">hackney</a>, while <a href="https://github.com/myfreeweb/httpotion" rel="noopener nofollow ugc">HTTPotion</a> is based on <a href="https://github.com/cmullaparthi/ibrowse" rel="noopener nofollow ugc">ibrowse</a>. HTTPoison’s options are <a rel="nofollow">documented</a> and found in the code <a href="https://github.com/edgurgel/httpoison/blob/master/lib/httpoison/base.ex#L393" rel="noopener nofollow ugc">here</a>. The ones that stick out are:</p>
<ul>
<li><code>:timeout</code> - timeout to establish a connection, in milliseconds. Default is 8000</li>
<li><code>:recv_timeout</code> - timeout used when receiving a connection. Default is 5000</li>
<li><code>:stream_to</code> - a PID to stream the response to</li>
</ul>
<p>An asynchronous example is found <a href="https://github.com/myfreeweb/httpotion#user-content-asynchronous-requests" rel="noopener nofollow ugc">here</a>.</p>
<p>The following code demonstrates the beginnings of using HTTPoison’s asynchronous functionality within a <code>GenServer</code> (without using <a href="https://hexdocs.pm/elixir/Task.html" rel="noopener nofollow ugc"><code>Task</code></a>):</p>
<pre><code>defmodule Poison do
  use GenServer

  defp handle_response(ref, response) do
    IO.puts "Received all response parts for request #{inspect ref}"
    IO.inspect response
  end

  defp handle_request_error(details) do
    IO.puts "A request failed with reason: #{inspect details.reason}"
  end

  defp async_request(response_map, timeout, recv_timeout) do
    url = "http://httparrot.herokuapp.com/get"
    body = ""
    headers = []
    options =[stream_to: self(), timeout: timeout, recv_timeout: recv_timeout]
    case HTTPoison.request :get, url, body, headers, options do
      {:ok, result} -&gt;
        Map.put response_map, result.id, [] # start collecting a new response
      {:error, details} -&gt;
        handle_request_error details
        response_map
    end
  end

  defp attach_response(response_map, response),
    do: Map.update! response_map, response.id, &amp;([response | &amp;1])

  def response_complete(response_map, ref) do
    case Map.get response_map, ref, :none do
      :none -&gt;
        {response_map, :none}
      parts_in_reverse -&gt;
        response_parts = Enum.reverse parts_in_reverse
        new_map = Map.delete response_map, ref
        {new_map, response_parts}
    end
  end

  defp response_error(response_map, error_msg) do
    new_map = Map.delete response_map, error_msg.id
    IO.puts "Request #{inspect error_msg.id} resulted in an error response with reason: #{inspect error_msg.reason}"
    new_map
  end

  ## callbacks: message handlers
  def handle_cast(:regular, state) do
    new_state = async_request state, 8000, 5000 # defaults
    {:noreply, new_state}
  end
  def handle_cast(:short_connect, state) do
    new_state = async_request state, 2, 5000
    {:noreply, new_state}
  end
  def handle_cast(:short_receive, state) do
    new_state = async_request state, 8000, 5
    {:noreply, new_state}
  end

  def handle_info(%HTTPoison.AsyncStatus{} = msg, state) do
    new_state = attach_response state, msg
    {:noreply, new_state}
  end
  def handle_info(%HTTPoison.AsyncHeaders{} = msg, state) do
    new_state = attach_response state, msg
    {:noreply, new_state}
  end
  def handle_info(%HTTPoison.AsyncChunk{} = msg, state) do
    new_state = attach_response state, msg
    {:noreply, new_state}
  end
  def handle_info(%HTTPoison.AsyncEnd{} = msg, state) do
    {new_state, response} = response_complete state, msg.id
    handle_response msg.id, response
    {:noreply, new_state}
  end
  def handle_info(%HTTPoison.Error{} = msg, state) do
    new_state = response_error state, msg
    {:noreply, new_state}
  end

  ## callbacks: lifecycle
  def init(_args) do
    {:ok, %{}} # use map to collect the various parts of the response
  end

  def terminate(_reason, _state) do
    :ok
  end

  ## public interface
  def start_link,
    do: GenServer.start_link __MODULE__, []

  def stop(pid),
    do: GenServer.stop pid

  ## client interface
  def short_connect(pid),
    do: GenServer.cast pid, :short_connect

  def short_receive(pid),
    do: GenServer.cast pid, :short_receive

  def regular(pid),
    do: GenServer.cast pid, :regular

end
</code></pre>
<p>.</p>
<pre><code>$ iex -S mix
iex(1)&gt; {:ok,pid} = Poison.start_link
{:ok, #PID&lt;0.398.0&gt;}
iex(2)&gt; Poison.short_connect pid     
:ok      
A request failed with reason: :connect_timeout
iex(3)&gt; Poison.short_receive pid
:ok      
Request #Reference&lt;0.0.6.4279&gt; resulted in an error response with reason: {:closed, :timeout}
iex(4)&gt; Poison.regular pid      
:ok      
Received all response parts for request #Reference&lt;0.0.6.4284&gt;
[%HTTPoison.AsyncStatus{code: 200, id: #Reference&lt;0.0.6.4284&gt;},
 %HTTPoison.AsyncHeaders{headers: [{"Connection", "keep-alive"},
   {"Server", "Cowboy"}, {"Date", "Thu, 15 Jun 2017 03:04:49 GMT"},
   {"Content-Length", "493"}, {"Content-Type", "application/json"},
   {"Via", "1.1 vegur"}], id: #Reference&lt;0.0.6.4284&gt;},
 %HTTPoison.AsyncChunk{chunk: "{\n  \"args\": {},\n  \"headers\": {\n    \"host\": \"httparrot.herokuapp.com\",\n    \"connection\": \"close\",\n    \"user-agent\": \"hackney/1.8.6\",\n    \"x-request-id\": \"db9e3183-036b-455f-bb9c-2c0dc379ce9a\",\n    \"x-forwarded-for\": \"72.39.127.107\",\n    \"x-forwarded-proto\": \"http\",\n    \"x-forwarded-port\": \"80\",\n    \"via\": \"1.1 vegur\",\n    \"connect-time\": \"0\",\n    \"x-request-start\": \"1497495889950\",\n    \"total-route-time\": \"0\"\n  },\n  \"url\": \"http://httparrot.herokuapp.com/get\",\n  \"origin\": \"10.171.119.12\"\n}",
  id: #Reference&lt;0.0.6.4284&gt;}]
iex(5)&gt; Poison.stop pid
:ok      
iex(6)&gt;  
</code></pre>
<p>Now one interesting thing to note is that the error for the <em>connection timeout</em> (as opposed to the <em>receive timeout</em>) is reported as a return value of <code>request</code>. This suggests that <code>request</code> actually <strong>blocks</strong> until it has established a connection - it is only from that point on that asynchronous operation begins.</p>
<p>It is therefore in your best interest to make the <code>:timeout</code> value much smaller than the default of 8000 (8 secs). The <code>:recv_timeout</code> can be longer as this is entirely handled by hackney (HTTPoison) and won’t lock up your <code>GenServer</code>.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="36953" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/task-await-terminates-genserver-because-of-timeout-how-to-fix/5987/43">Post #42</a>
	                </div>
	            </div>
              <div id="likers-container-36953" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="36953"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #42"></div>
  </section>
</div>
    <div class="postbit" id="36969" data-post-id="36969">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="yurko" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/yurko/120/2369_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  yurko
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="kaa.python" data-post="15" data-topic="5987">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/k/e36b37/48.png" class="avatar"> kaa.python:</div>
<blockquote>
<p>I need to use GenServer because I have a bunch of user with some data for which i need to poll an external website every N seconds.</p>
</blockquote>
</aside>
<p>here’s a parallel crawl function, it’s called from a genserver process and handles timeouts. You can do something similar:</p>
<pre><code>@doc """
Crawl a list of URLs and return responses.
"""
@spec crawl(list()) :: List
def crawl(list) do
  list
  |&gt; Enum.map(&amp;Task.Supervisor.async(TaskSupervisor, fn() -&gt; visit(&amp;1) end))
  |&gt; Enum.map(fn(task_id) -&gt;
    try do
      Task.await(task_id, 18_000)
    catch _reason, _info -&gt;
      {:timeout, "Process reached timeout while making an HTTP request"}
    end
  end)
end
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="36969" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/task-await-terminates-genserver-because-of-timeout-how-to-fix/5987/44">Post #43</a>
	                </div>
	            </div>
              <div id="likers-container-36969" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="36969"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #43"></div>
  </section>
</div>
    <div class="postbit" id="37034" data-post-id="37034">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="kaa.python" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  kaa.python
                      <span class="op-star" title="Thread Starter">
                        <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                      </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<ol>
<li>because of Enum.map, in the worst case it’ll return a value in 18 seconds blocking the control flow. how is better?</li>
<li>how try .. catch will prevent it from sending the :exit message ?</li>
</ol> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="37034" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/task-await-terminates-genserver-because-of-timeout-how-to-fix/5987/45">Post #44</a>
	                </div>
	            </div>
              <div id="likers-container-37034" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="37034"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #44"></div>
  </section>
</div>
    <div class="postbit" id="37045" data-post-id="37045">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="yurko" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/yurko/120/2369_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  yurko
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="kaa.python" data-post="45" data-topic="5987" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/k/e36b37/48.png" class="avatar"> kaa.python:</div>
<blockquote>
<ol>
<li>because of Enum.map, in the worst case it’ll return a value in 18 seconds blocking the control flow. how is better?</li>
</ol>
</blockquote>
</aside>
<p>the control flow of this process is “visiting N urls every X seconds”, this list will be crawled as long as the longest url will take, so there is no unnecessary blocking unless I didn’t understand your situation</p>
<aside class="quote no-group" data-username="kaa.python" data-post="45" data-topic="5987" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/k/e36b37/48.png" class="avatar"> kaa.python:</div>
<blockquote>
<ol start="2">
<li>how try .. catch will prevent it from sending the :exit message ?</li>
</ol>
</blockquote>
</aside>
<p>after timeout the task will error out, this error can be caught but you can also trap the exit message. In any case it would be an exception, normally you’d get an error response after 5-10 seconds</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="37045" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/task-await-terminates-genserver-because-of-timeout-how-to-fix/5987/46">Post #45</a>
	                </div>
	            </div>
              <div id="likers-container-37045" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="37045"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #45"></div>
  </section>
</div>
    <div class="postbit" id="37046" data-post-id="37046">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="NobbZ" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/NobbZ/120/27235_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  NobbZ
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><code>Task.await</code> will not error out it will <code>exit/1</code>, which is not catchable:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">iex(2)&gt; try do
...(2)&gt;   exit("foo")
...(2)&gt; catch
...(2)&gt;   _ -&gt; :catched
...(2)&gt; end
** (exit) "foo"
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="37046" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/task-await-terminates-genserver-because-of-timeout-how-to-fix/5987/47">Post #46</a>
	                </div>
	            </div>
              <div id="likers-container-37046" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="37046"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #46"></div>
  </section>
</div>
    <div class="postbit" id="37048" data-post-id="37048">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="kaa.python" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  kaa.python
                      <span class="op-star" title="Thread Starter">
                        <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                      </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="yurko" data-post="46" data-topic="5987">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/yurko/48/2369_2.png" class="avatar"> yurko:</div>
<blockquote>
<p>the control flow of this process is “visiting N urls every X seconds”, this list will be crawled as long as the longest url will take, so there is no unnecessary blocking unless I didn’t understand your situation</p>
</blockquote>
</aside>
<p>the current thread will be blocked. what’s not clear?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="37048" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/task-await-terminates-genserver-because-of-timeout-how-to-fix/5987/48">Post #47</a>
	                </div>
	            </div>
              <div id="likers-container-37048" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="37048"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #47"></div>
  </section>
</div>
    <div class="postbit" id="37049" data-post-id="37049">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="NobbZ" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/NobbZ/120/27235_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  NobbZ
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Well, somewhere you <strong>have</strong> to wait, or you hadn’t choosen a call from the beginning, hadn’t you?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="37049" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/task-await-terminates-genserver-because-of-timeout-how-to-fix/5987/49">Post #48</a>
	                </div>
	            </div>
              <div id="likers-container-37049" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="37049"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #48"></div>
  </section>
</div>
    <div class="postbit" id="37076" data-post-id="37076">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="peerreynders" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/peerreynders/120/5826_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  peerreynders
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Actually <code>exit/1</code> can be caught:</p>
<pre><code>iex(1)&gt; try do
...(1)&gt;   exit("foo")
...(1)&gt; catch 
...(1)&gt;   :exit, _ -&gt; :caught
...(1)&gt; end
:caught
</code></pre>
<p>however your objection is still intact:</p>
<ul>
<li>the timeout doesn’t have anything to do with the <code>Task</code>, which just keeps running - it is the <code>await/2</code> process that times out</li>
<li>the termination of the <code>await/2</code> process emits an exit <em>signal</em> to all linked processes. <em>That</em> exit signal cannot be “caught” - the exit signal will terminate any linked processes which aren’t trapping exits and those which do trap exits will get an <code>:EXIT</code> message in their mailbox.</li>
</ul>
<p>.</p>
<ol>
<li>
<p><a href="https://hexdocs.pm/elixir/Kernel.html#exit/1" rel="noopener nofollow ugc"><code>Kernel.exit/1</code></a> can <em>only</em> be caught inside the process that invokes it - if it is allowed to escape the process it turns into an exit <em>signal</em> - at which point it is too late to <code>catch</code> it anywhere.</p>
</li>
<li>
<p><a href="https://hexdocs.pm/elixir/Process.html#exit/2" rel="noopener nofollow ugc"><code>Process.exit/2</code></a> is an entirely different animal. While <code>exit/1</code> terminates the process that invokes it, <code>exit/2</code> sends an exit signal to the specified process <em>usually</em> with the intent to “<em>tell</em> that process to terminate”. So <code>exit/2</code> cannot be caught under any circumstances (but it can be <em>trapped</em> - unless the reason is <code>:kill</code>).</p>
</li>
</ol>
<p>.</p>
<pre><code>iex(2)&gt; try do
...(2)&gt;   Process.exit(self(),"foo")
...(2)&gt; catch                       
...(2)&gt;   :exit, _ -&gt; :caught       
...(2)&gt; end                         
** (EXIT from #PID&lt;0.87.0&gt;) "foo"
</code></pre>
<p>.</p>
<pre><code>iex(1)&gt; Process.flag :trap_exit, true 
false
iex(2)&gt; try do                       
...(2)&gt;   Process.exit(self(),"foo") 
...(2)&gt; catch                        
...(2)&gt;   :exit, _ -&gt; :caught        
...(2)&gt; end                          
true
iex(3)&gt; flush()
{:EXIT, #PID&lt;0.103.0&gt;, "foo"}
:ok
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="37076" data-batch-url="/posts/batch_likers">
                        3
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/task-await-terminates-genserver-because-of-timeout-how-to-fix/5987/50">Post #49</a>
	                </div>
	            </div>
              <div id="likers-container-37076" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="37076"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-most-liked cat-most-liked" title="One of the top 3 liked posts in this thread!"></div>
  </section>
</div>
    <div class="postbit" id="37094" data-post-id="37094">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="kaa.python" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  kaa.python
                      <span class="op-star" title="Thread Starter">
                        <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                      </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>no[quote=“NobbZ, post:49, topic:5987, full:true”]<br>
Well, somewhere you have to wait<br>
[/quote]</p>
<p>no. why?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="37094" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/task-await-terminates-genserver-because-of-timeout-how-to-fix/5987/51">Post #50</a>
	                </div>
	            </div>
              <div id="likers-container-37094" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="37094"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #50"></div>
  </section>
</div>
    <div class="postbit" id="37096" data-post-id="37096">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="NobbZ" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/NobbZ/120/27235_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  NobbZ
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Your original plan does do the work in a <code>handle_call/3</code>, so the caller will wait for an answer until that <code>GenServer.call</code> times out or it gets a reply. Sou you have to wait.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="37096" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/task-await-terminates-genserver-because-of-timeout-how-to-fix/5987/52">Post #51</a>
	                </div>
	            </div>
              <div id="likers-container-37096" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="37096"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #51"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <a class="load-more-button" data-turbo-stream="true" href="/topics/5987/load_more?page=6">Load more posts</a>
</div></template></turbo-stream>