Fork me on GitHub

should I explict close! the chan when I dont need it?


that code would go into a very fast loop if so (if it never parks in the ...) because you are not checking the value of <! and it returns nil instantly for a closed chan


usually you would want (try (when-some [next-item (<! c)] ... (recur) (catch ...)) to prevent the hot loop


@doglooksgood If you close it, this will ensure that any blocked or parked takes via <!! and <! will return nil (note that even after a channel is close!d, a take will return data in the buffer, until it is empty). For example, if you have a go loop parked on a take, then when you close the channel, it will receive nil and depending on how you've coded it (i.e., check the value you get from the chan, and if it's nil, do not recur), the code in the go block will no longer be executing. Likewise, puts via >!! and >! will return false instead of blocking/parking.


hello everyone

(defn five-seconds-loop
  [poison in-chan]
  (async/go-loop []
    (let [[data chosen] (async/alts! [poison in-chan])]
      (when (not= chosen poison)
        (if (some? data)
        (async/<! (async/timeout 5000))
id like this whole loop code block to take at 5 seconds at maximum to execute including the time do-stuff and reading from in-chan takes if the code isnt able to execute in 5 seconds the loop should start again is it possible?


@plins if data is ever nil you should stop calling recur at that point


(that is, if it came from in-chan and is nil)


if it should start every 5 seconds, why not (go-loop [] (do-it) (<! (timeout 5000)) (recur)) where do-it is a call to go with your let block without the recur