Fork me on GitHub
#core-async
<
2019-12-07
>
erwinrooijakkers12:12:31

Question xpost from #clojure:

erwinrooijakkers12:12:33

(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?

erwinrooijakkers12:12:32

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

erwinrooijakkers12:12:37

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

erwinrooijakkers12:12:41

I thinkt here’s a timing issue

erwinrooijakkers12:12:47

Channel closed before program is finished or something

erwinrooijakkers13:12:19

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

erwinrooijakkers16:12:43

I see i had to wait before reading

erwinrooijakkers16:12:50

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

p-himik16:12:38

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

dabrazhe20:12:59

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]
  (go 
     (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.

hiredman23:12:56

take! takes a callback