プロセスが終了したときに結果を含む core.async チャネルを返す長時間実行プロセスがあります。
ここで、HTTP-kit を使用したロング ポーリングを使用してその結果を返したいと思います。残念ながら、私はそうする正しい方法が何であるかについて少し混乱しています。
現在、処理呼び出しを開始し、完了時に結果を送信するハンドラー (ルートに接続) があります。
(defn handler
[request]
(let [c (process request)] ;; long running process that returns a channel
(http/with-channel request channel
(http/send! channel {:status 200
:body (<!! (go (<! c)))))
(http/on-close channel (fn [_] (async/close! c))))))
動作しますが、これが正しい方法かどうかはわかりません。
編集はブロックされているため<!!
、現在、ゴーループで非ブロックバリアントを試しています
(defn handler
[request]
(let [c (process request)]
(http/with-channel request channel
(async/go-loop [v (<! c)]
(http/send! channel {:status 200
:body v}))
(http/on-close channel (fn [_] (async/close! c))))))