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


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="sahilpaudel" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sahilpaudel/120/18807_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  sahilpaudel
                    <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>Hi <a class="mention" href="/u/nobbz" rel="nofollow">@NobbZ</a>, <a class="mention" href="/u/lucaong" rel="nofollow">@lucaong</a></p>
<p>I have used following approach</p>
<p>Controller</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def create(conn, %{"file" =&gt; %Plug.Upload{path: fullpath, content_type: "text/csv"}, "email" =&gt; email}) do
    conn
      |&gt; render_json_response({:ok, %{message: "Request Initiated"}})
    CSVParser.call(fullpath, email)
  end
</code></pre>
<p>CSVParser.ex</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def call(csv_path, email) do
    task = Task.async(fn -&gt; do_async_task(csv_path, email) end)
    Task.await(task, :infinity)
  end

  def do_async_task(csv_path, email) do
    csv_path
      |&gt; read_csv
      |&gt; dump_to_csv
      |&gt; add_attachment
      |&gt; Email.create(email)
      |&gt; Email.send_email
  end
</code></pre>
<p>But If i hit the api simultaneously the other request is not returning <code>Request Initiated</code> they just keep waiting.</p>
<p>Also I am getting this error message</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">expected action/2 to return a Plug.Conn, all plugs must receive a connection (conn) and return a connection.
</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="171194" 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/how-to-process-data-asynchronously-in-elixir/30646/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-171194" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="171194"
                     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 #11"></div>
  </section>
</div>
    <div class="postbit" id="171197" data-post-id="171197">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Yes, that’s because <code>CSVParser.call</code> (and therefore <code>Controller.create</code>) still blocks by awaiting the task. As I wrote above, if you don’t care about the result, you can use <code>Task.start_link/1</code>. The controller in your case does not need to wait for the email to be sent, so in <code>CSVParser</code> you can do this:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def call
  Task.start_link(fn -&gt; do_async_task(csv_path, email) end)
end
</code></pre>
<p>Also, controller functions should always return <code>conn</code> (as the error message says). So make sure you return <code>conn</code> in your <code>create</code> method:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def create(conn, %{"file" =&gt; %Plug.Upload{path: fullpath, content_type: "text/csv"}, "email" =&gt; email}) do
  CSVParser.call(fullpath, email)
  conn |&gt; render_json_response({:ok, %{message: "Request Initiated"}})
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="171197" 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/how-to-process-data-asynchronously-in-elixir/30646/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-171197" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="171197"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-solved cat-solved" title="Marked as solution"></div>
  </section>
</div>
    <div class="postbit" id="171204" data-post-id="171204">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="sahilpaudel" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sahilpaudel/120/18807_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  sahilpaudel
                    <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>Thank you <a class="mention" href="/u/lucaong" rel="nofollow">@lucaong</a> this is what I was looking for as of now.<br>
I may have to deal with the result later on but this is perfect for now.</p>
<p>Also in your spare time do let me know how can we go about this by using <code>Task.Supervisor</code> because it gave me no process alive whenever I tried it.</p>
<p>And Thank you <a class="mention" href="/u/nobbz" rel="nofollow">@NobbZ</a> for all the insights can’t mark both as answers but your answer really helped me understand the stuff I was trying to do.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="171204" 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/how-to-process-data-asynchronously-in-elixir/30646/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-171204" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="171204"
                     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="171246" data-post-id="171246">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>You need to pass an actually running supervisor into task.supervisor.start…</p>
<p>You probably put a symbol in there that wasn’t a supervisor.  Usually you start your supervisors in your Application module, then it’s available at runtime and you can use it in your 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="171246" 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/how-to-process-data-asynchronously-in-elixir/30646/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-171246" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="171246"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>