【发布时间】:2015-11-16 08:10:15
【问题描述】:
我一直在 swanodette 的代码中看到这个宏 <?,看起来非常有用:
在这个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)))))
<?只是一个宏糖,扩展成类似的东西 (抛出错误(<![expr]))。在 core.async<!中的目的与 ES6 的收益操作符。如果异步进程将错误写入 它的通道我们会将其转换为异常。
但我找不到它的定义。 Clojure{Script} 中是如何实现的?
【问题讨论】:
-
仅供参考:他所有的代码都在 github 上:github.com/swannodette/swannodette.github.com 您要查找的文件:
macros.clj&helpers.cljs -
@Andre 谢谢!我在找那个! (在 github 上搜索 不起作用)
标签: asynchronous clojure macros clojurescript