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'?
-- Jonathon McKitrick On Sat, Dec 20, 2014 at 10:56 PM, Chris Freeman <cwfree...@gmail.com> wrote: > I'm a little uncertain exactly what your code is trying to do, but I > believe you're trying to notify a bunch of connections after your speaker > notification emails are sent. > > In which case, I'd do something like this: > > (defn send-notifications [] > (try > (mailer/send-speaker-confirmation-notification 1 "http://localhost") > true > (catch Exception e > (println (.getMessage e)) > false))) > > (defn test-mailer [] > (let [done (async/thread-call send-notifications)] > (when-let [status (async/<! done)] > (doseq [chan @connections] > (async/>! chan (pr-str "Done" status)))))) > > I've replaced the string "Success" with an explicit true and added an > explicit false. I'd prefer if send-speaker-confirmation-notification > returned a truthy value, but I don't know that it does. > > In your original, the doseq call was done in a separate thread. If you'd > still like that, wrap the when-let in a async/go call, as followings: > > (defn test-mailer [] > (let [done (async/thread-call send-notifications)] > (async/go > (when-let [status (async/<! done)] > (doseq [chan @connections] > (async/>! chan (pr-str "Done" status))))))) > > But if you do, keep in mind that the main thread will end before the other > two threads do, and that's probably unhealthy. > > Chris > > On Sat, Dec 20, 2014 at 9:17 PM, Jonathon McKitrick <jmckitr...@gmail.com> > wrote: > >> I'd like to implement a thread that will send an email, then send a >> response via websocket to the client when the send completes. >> >> (defn my-wait-loop [] >> (async/go-loop [status (async/<! @mailer-status)] >> (if status >> (do >> (println "Ready to send " status) >> (doseq [chan @connections] >> (println "Channel" chan) >> (send! chan (pr-str "Done" status))) >> (recur (async/<! @mailer-status))) >> (println "Go away")))) >> >> (defn test-mailer [] >> ;;(my-wait-loop) >> (reset! mailer-status >> (async/thread >> (try >> (mailer/send-speaker-confirmation-notification 1 " >> http://localhost") >> (catch Exception e >> (println (.getMessage e)))) >> "Success"))) >> >> I would like to have the go-loop inside my-wait-loop run at all times, >> waiting for mailer-status to have a value. >> But I believe that can never happen, since the go-loop is waiting on an >> empty channel, and the reset! with the mailer will replace the channel with >> a new one after the emails are sent. >> >> Is there a batter way to do this, without needing to call my-wait-loop >> before the email thread is dispatched? >> >> -- >> 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. >> > > -- > 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 a topic in the > Google Groups "Clojure" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/clojure/f9J_CBPoc5U/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- 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.