I have a top level core.async loop. I want it to work endlessly, at least until I pass it on, so that it stops with CTRL-C or kill or similar. I am currently using java.lang.Runtime / addShutdownHook as follows:
(ns async-demo.core (:require [clojure.core.async :as async :refer [<! >! <!! timeout chan alt! go]])) (defn run [] (go (loop [] (recur)))) (.addShutdownHook (Runtime/getRuntime) (Thread. #(println "SHUTDOWN")))
Here are my problems:
If I run REPL and (run) , then it starts and starts in the background thread. When I exit REPL, I do not see the desired completion message.
However, when I run from lein run , the go loop immediately exits and displays "SHUTDOWN".
I do not want either.
I do not necessarily expect to find a solution that works for all JVMs. I am developing on a Mac and deploying Ubuntu, so I would like to find a solution that works for both:
Mac JVM: java version "1.7.0_45" Java (TM) SE Runtime Environment (build 1.7.0_45-b18) Java Virtual Machine HotSpot β’ TM (build 24.45-b08, mixed mode)
Ubuntu JVM: java version "1.7.0_25" OpenJDK runtime (IcedTea 2.3.10) (7u25-2.3.10-1ubuntu0.12.04.2) 64-bit server version of OpenJDK (build 23.7-b01, mixed mode)
java signals clojure core.async
David J.
source share