我是新手使用Clojure,正在编写一个库将POST结果发送到服务器进行响应。我通过将响应放入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
它可以工作,但我很难验证是否这是正确的方法。