I think this is solution is fine. A single channel is not going to use any 
noticeable resources. You've basically created a latch - there are several 
latch-like things built into Java you can use as well. 

In the main thread you could do:
(let [signal (java.util.concurrent.CountDownLatch. 1)]
  ... launch your work
  (.await signal))

And in the signal handler you then:
(.countdown signal)

You could also use a Lock and Condition (the oo version of wait/notify), or 
a Semaphore, or a CyclicBarrier.

On Friday, August 5, 2016 at 11:38:24 PM UTC-5, Richard Möhn wrote:
>
> I'm using core.async. In my application the main thread creates a few 
> channels, starts a few go blocks and that's it. When I run it as a 
> stand-alone (i.e. not in the REPL), it starts those go blocks and then 
> exits. After being surprised initially, I understand why this happens: the 
> main thread has nothing more to do, so it terminates and with it the 
> application.
>
> However, I want the application to run until it receives SIGTERM, for 
> example. My current solution is to have a channel wait-for-exit and the 
> main thread does a
> (<!! wait-for-exit)
> after starting its go routines and the signal handler does a
> (put! wait-for-exit :ok)
> This blocks the main thread until the signal handler is called and the 
> application shut down.
>
> It also wastes the resources allocated to the main thread. (Which is only 
> a little bit of RAM, as far as I know, so not too bad.) What is the usual 
> way to solve this problem? Let the main thread do the work of one of the go 
> routines?
>
> Best,
>
> Richard
>

-- 
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.

Reply via email to