Fork me on GitHub

Question xpost from #clojure:


(require '[clojure.core.async :as async :refer [go-loop chan >! <!! close!]]

(defn tst [out]
  (go-loop [[x & xs] (range 5)]
    (when (seq xs)
      (println "now here:" x)
      (>! out x)
      (recur xs))))
Why does this:
(def out (chan 2000))
(tst out)
(close! out)
(println "value here: " (<!! (async/into [] out)))
Print: > now here: 0 > now here: 1 > now here: 2 > now here: 3 > value here: [0 1 2 3] And this:
(let [out (chan 2000)]
  (tst out)
  (close! out)
  (println "value here: " (<!! (async/into [] out))))
Print: > now here: 0 > value here: now here:[ ]1 > now here: 2 > now here: 3 Why does putting it in a let block lead to async output? And not return the full vector of values?


My goal is to have a function that uses channels but returns a value (not a channel);


Hmm when I debug and halt on every step it does return properly


I thinkt here’s a timing issue


Channel closed before program is finished or something


Values are not yet delivered, but I already read them via async/into


I see i had to wait before reading


E.g., (<!! (async/timeout 100))


I don't think that's a robust solution because the rate with which you generate the number could change.


Hi. I am stuck with using core.async in AWS Lambda handler in Clojurescript. The Lambda handler invokes the callback function, and returns as lambda function's result. The issue I am having is how to return a value when reading a channel, eg outside of a go block. take! just returns nil, while (go ..) block returns yet another channel.

(defn handlerfunc [event context callback]
     (callback nil (clj->js  {:body (str (<! ch))}) ))) 
In this example I am stuck with the channel while I need the value of (<! ch) The handlerfunc needs to have a value returned by the last statement. Printing doesn't help, obviously, and there are no blocking <!! macros in CLJS.


take! takes a callback