我是 clojure 的新手,正在编写一个库,将发布结果发送到服务器以获取响应。我通过将响应放在 core.async 通道上来使用它。这是理智还是有更好的方法?
这是我正在做的事情的高级概述:
(defn my-post-request [channel options]
(client/post http://www.example.com options
(fn [{:keys [status headers body error]}] ;; asynchronous handle response
(go (>! channel body)))))
(defn request-caller [options]
(let [channel (chan)]
(my-post-request channel options)
(json/parse-string (<!! (go (<! channel))))))
这是我正在使用的实际代码:https ://github.com/gilmaso/btc-trading/blob/master/src/btc_trading/btc_china.clj#L63
它有效,但我很难验证这是否是解决此问题的正确方法。