【问题标题】:Get information out of go block从 go 块中获取信息
【发布时间】:2016-04-14 17:43:39
【问题描述】:

我有以下 ClojureScript 代码来发出 POST 请求:

(defn perform-post [resource]
  "Performs a post and returns the body :)"
  (go (let [response (<! (http/post resource))]
        (:body response))))

当我调用返回数字的资源时

(js/console.log (perform-post post-create-recipe-url))

打印出来:

buf
对象 { buf={...}, n=1, cljs$lang$protocol_mask$partition0$=2,
更多...}
buf
对象 { head=1, tail=0, length=1, meer...} arr

[“6276677237104933520”,未定义]

我想获取“6276677237104933520”(帖子正文)信息作为“返回”值。

我怎样才能做到这一点?我试过&lt;!!,但它没有工作,因为它没有定义。

【问题讨论】:

    标签: clojure clojurescript core.async


    【解决方案1】:

    阻塞语义 (&lt;!!) 在 ClojureScript 平台上不可用。

    您只能在 go 块内从通道中检索值:

    (go (js/console.log (<! (perform-post post-create-recipe-url))))
    

    【讨论】:

    • 谢谢!我正在使用一个原子并将值分配给它。我以后需要它:)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-06
    • 2021-06-07
    • 1970-01-01
    • 2021-01-06
    • 1970-01-01
    • 2019-09-03
    相关资源
    最近更新 更多