On Dec 21, 2014 7:17 AM, "Jonathon McKitrick" <jmckitr...@gmail.com> wrote:
> Well, my goal is to start a go-loop (if possible) at the root level of the > code that simply parks and waits for a group of emails to be sent. When > that happens, it would wake up and broadcast the result of the send > operation via web socket back to the browser. I'd like to avoid starting > that loop every time I send the emails, and I was under the impression that > could be done with a go-loop, which would park until the channel had values > to consume. But you are saying that might be 'unhealthy'? > > You want to avoid a situation where your main thread tries to exit before your worker threads are done. If that's not a possibility, then don't worry about it. (I hope I'm not confusing JVM behaviors with behaviors in other languages and runtimes.) A go-loop is entirely appropriate for what you're trying to do. I think the issue you're running into is that thread creates a new channel for each individual call. Instead, consider creating a channel, and let your email sender loop, writing success to that channel after each . Then your go-loop just reads from the thread like you already have it doing. A basic example might be: (defn sender-receiver-example [] (let [successes (async/chan)] ;; Thread to send emails (async/go (doseq [email-group source-of-emails] (send-emails email-group) (async/>! successes "Success")) ;; You could also send the email addresses instead of "Success" (async/close! xs-done)) ;; Without this, the consumer go-loop will never terminate. ;; Thread to notify browsers (loop [success (async/<! successes)] (when-not (nil? success) (tell-your-browsers) (recur (async/<! successes)))))) Chris -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.