Clojurescript core-async: Async state inside go

I have a problem with ClojureScript Core-Async. This only happens in ClojureScript, not 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 called, the (foo :ok)result will be as expected - the function ccis called twice, and the console displays cc: :ok cc: :ok after and. But at startup, the (foo 1)function ccalso runs twice, and the console shows cc: 1 cc: :ok. So, although the first condition is not filled, the second is still verified!

+4
source share
1 answer

This is definitely a bug in the ClojureScript core.async library. To do this, I opened the Jira issue .

In the meantime, I managed to get around this using:

(go
  (when (= :ok (<! (cc x))
    (when (= :ok (<! (cc :ok)))
      (print "after and")))))
0

Source: https://habr.com/ru/post/1625987/


All Articles