3
チャンク状態で数秒間接続を開いたままにすることはできますか?エリクシールプラグ接続をチャンクモードで開く
私が終了する5秒を言うことができますし、その後、私はクライアントにチャンクを経由して応答を送信したいかかりますが、接続はを閉じて、私は郵便配達でこれをテストしていると私は、このヘッダを持っているいくつかのプロセスを作成する要求に
:
"接続": "キープアライブ"、 "キープアライブ":
"= 10000タイムアウトは、" これは私の最小化されたアプリケーション、出力され、常に "InitEnd" 望ましい結果であります: "Init1234このような567789End」か何か:
defmodule AlivePlug do
import Plug.Conn
def init(opts) do
opts
end
def call(conn, _opts) do
conn = send_chunked(conn, 200)
# send initial chunk
chunk(conn, "Init")
pid = start_thread
# create 10 async processes which does somthing for 5 seconds and then sends result via chunk
1..10
|> Enum.each(fn num ->
send pid, {conn, num}
end)
# send End as a symbol of last chunk
chunk(conn, "End")
conn
end
defp start_thread, do: spawn_link(fn -> thread_listener end)
defp thread_listener do
receive do
{conn, num} ->
:timer.sleep(5000)
# problem is here :(
# chunk returns {:error, :closed}
{:error, :closed} = chunk(conn, "#{num}")
thread_listener
_ ->
thread_listener
end
end
end
代わりに別の接続を開いて、応答を送信することは可能でしょうか? – vikram7