Ah, very nice. I had not seen the alt! macro in use but upon close look
it is just what I need when using the :default option. My go-loop macro
now only requires the single stop channel:
(defmacro go-loop [bindings & body]
(let [stop (first bindings)]
`(let [~stop (chan)]
(go (wh
This approach works for the simple case but gets cumbersome it a more
realistic loop with several timeouts and conditional logic. For
example, here is a reduced use case which I am using my go-loop macro I
posted earlier:
(let [heads? (fn [] (> (rand) 0.5))
heads-time-out 1
lo
You can also use the alt! macro:
(let [stop (chan)]
(go (loop []
(println "Hello World!")
(alt!
(timeout 1000) (do (println "I'm done sleeping...")
(recur))
stop :ok)))
(!! stop :now)
(println "We're done."))
On Wednesday, July
Why not the following?
(let [stop (chan)]
(go (loop []
(println "Hello World!")
(let [[v c]] (alts! [(timeout 1) stop])]
(if (= c stop)
:done
(do (println "I'm done sleeping, going to recur now...")
(recur)))
On Wed, Jul 1
Hi all,
In a number of places where I'm trying core.async I have run across the
pattern of having a loop inside a go block with some timeouts in the
loop body. Contrived example:
(go
(while true
(println "Hello World!")
(In situations like these I almost always want to