I have a problem with ClojureScript Core-Async . This only happens in ClojureScript and not in Clojure.
I have the following code:
(defn cc [x]
(go
(println "cc: " x)
x))
(defn foo [x]
(go
(when (and (= :ok (<! (cc x)))
(= :ok (<! (cc :ok))))
(print "after and"))))
(foo 1)
(foo :ok)
When calling (foo :ok)
, the result is as expected - the function cc
is called twice, and the console shows cc: :ok cc: :ok after and
. But, when running (foo 1)
, the function cc
is also run twice and the console shows cc: 1 cc: :ok
. So, even though the first condition isn't fullfilled, the second one is still checked!
This is appraently a bug with the ClojureScript core.async library. I opened a Jira issue for this.
In the meantime I was able to work around this by using:
(go
(when (= :ok (<! (cc x))
(when (= :ok (<! (cc :ok)))
(print "after and")))))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.