【问题标题】:How does the binding function work with core.async?绑定函数如何与 core.async 一起工作?
【发布时间】:2015-10-13 01:55:24
【问题描述】:

可以通过 core.async 使用绑定吗?我正在使用 ClojureScript,所以 core.async 非常不同。

(def ^:dynamic token "no-token")
(defn call 
  [path body] 
  (http-post (str host path) (merge {:headers {"X-token" token}} body)))) ; returns a core.async channel
(defn user-settings
  [req]
  (call "/api/user/settings" req))
; elsewhere after I've logged in
(let [token (async/<! (api/login {:user "me" :pass "pass"}))]
  (binding 
    [token token] 
    (user-settings {:all-settings true})))

【问题讨论】:

    标签: clojure clojurescript


    【解决方案1】:

    在 ClojureScript1 中,binding 基本上是 with-redefs 加上额外检查所涉及的变量是否标记为 :dynamic。另一方面,gos 被安排在块中执行1(也就是说,它们可能被“停放”并稍后恢复,go 块之间的交错是任意的)。这些模型根本不能很好地啮合。

    简而言之,不,请改用显式传递的参数。


    1 Clojure 中细节不同,但结论是一样的。

    2 使用可能的最快机制,setTimeout,如果没有更好的可用时间,则为 0。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-17
      • 1970-01-01
      • 2019-11-21
      • 1970-01-01
      • 1970-01-01
      • 2022-06-14
      • 2021-07-01
      • 1970-01-01
      相关资源
      最近更新 更多