core-async

erwinrooijakkers 2019-12-07T12:42:35.259300Z

Hi all

erwinrooijakkers 2019-12-07T12:43:31.260400Z

Question xpost from #clojure:

erwinrooijakkers 2019-12-07T12:43:33.260600Z

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

erwinrooijakkers 2019-12-07T12:44:32.261100Z

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

erwinrooijakkers 2019-12-07T12:52:37.261900Z

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

erwinrooijakkers 2019-12-07T12:52:41.262200Z

I thinkt here’s a timing issue

erwinrooijakkers 2019-12-07T12:52:47.262500Z

Channel closed before program is finished or something

erwinrooijakkers 2019-12-07T13:19:19.263Z

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

erwinrooijakkers 2019-12-07T13:19:20.263100Z

Hmm

erwinrooijakkers 2019-12-07T16:03:43.265200Z

I see i had to wait before reading

erwinrooijakkers 2019-12-07T16:03:50.265400Z

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

p-himik 2019-12-07T16:10:38.265900Z

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

dabrazhe 2019-12-07T20:03:59.267500Z

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 (&lt;! 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.

2019-12-07T23:49:56.268400Z

take! takes a callback