我经常看到swanodette的代码中使用的这个宏
在这个gist中:
在这篇博客文章中:
<?
,看起来非常有用:在这个gist中:
;; BOOM!!! we can convert async errors into exceptions
(go (try
(let [x (<? (run-task (.-readFile fs) "foo.txt" "utf8"))]
(.log js/console "Success" x))
(catch js/Error e
(.log js/console "Oops" e))))
在这篇博客文章中:
(go (try
(let [tweets (<? (get-tweets-for "swannodette"))
first-url (<? (expand-url (first (parse-urls tweets))))
response (<? (http-get first-url))]
(. js/console (log "Most recent link text:" response)))
(catch js/Error e
(. js/console (error "Error with the twitterverse:" e)))))
<?
只是一个宏,会扩展成类似于(throw-err (<!
[expr]))的东西。在core.async中,<!
与ES6的yield操作符具有相同的作用。如果异步进程将错误写入其通道,我们将将其转换为异常。
但我找不到它的定义。它在Clojure{Script}中是如何实现的?
macros.clj
和helpers.cljs
。 - ClojureMostly