[英]Get information out of go block
I have the following ClojureScript code to make a POST request: 我有以下ClojureScript代码来发出POST请求:
(defn perform-post [resource]
"Performs a post and returns the body :)"
(go (let [response (<! (http/post resource))]
(:body response))))
When I make a call to a resource which returns a number 当我调用返回数字的资源时
(js/console.log (perform-post post-create-recipe-url))
This prints: 打印:
buf BUF
Object { buf={...}, n=1, cljs$lang$protocol_mask$partition0$=2, 对象{buf = {...},n = 1,cljs $ lang $ protocol_mask $ partition0 $ = 2,
more...} 更多...}
buf BUF
Object { head=1, tail=0, length=1, meer...} arr 对象{head = 1,tail = 0,length = 1,meer ...} arr
["6276677237104933520", undefined] [“ 6276677237104933520”,未定义]
I want to obtain the "6276677237104933520" (the post body) information as a "return" value. 我想获取“ 6276677237104933520”(邮件正文)信息作为“返回”值。
How can I accomplish this? 我该怎么做? I tried <!!
我试过了<!!
but it does not work since it is not defined. 但由于未定义,因此无法使用。
Blocking semantics ( <!!
) is not available on ClojureScript platform. 阻塞语义( <!!
)在ClojureScript平台上不可用。
You can retrieve value from a channel only within go
block: 您只能在go
块内从通道检索值:
(go (js/console.log (<! (perform-post post-create-recipe-url))))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.