我有以下 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
Object { buf={...}, n=1, cljs$lang$protocol_mask$partition0$=2,
more...}
buf
Object { head=1, tail=0, length=1, meer...} arr
["6276677237104933520", undefined]
我想获取“6276677237104933520”(帖子正文)信息作为“返回”值。
我怎样才能做到这一点?我试过<!!
但它不起作用,因为它没有定义。
最佳答案
阻止语义 ( <!!
) 在 ClojureScript 平台上不可用。
您只能从 go
范围内的 channel 检索值 block :
(go (js/console.log (<! (perform-post post-create-recipe-url))))
关于clojure - 从 go block 中获取信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36630320/