immutant 2016-06-29

@richiardiandrea: I'm trying to understand what your needs are - would you mind stating your use case?

@tcrawley: thanks for asking but on my side I solved, see snippet above

your wait-for-close?

Yep, I put this in my main and it blocks until the server exits

what is triggering the server to exit? a ^-C? or are you calling web/stop somewhere?

Yes I call stop as part of the app life cycle, and the start is executed in separate thread

hmm. I'm glad that works for you, but it really shouldn't :) Fns registered with at-exit will only be called when the JVM exits

I'll try it locally

Oh, ok...just put a mount defstate and that snippet in the main together with a a mount/start before it

To have the same situation as here

I've never used mount, so wouldn't know where to start :)

(ns exit.core
  (:require [immutant.web :as web])
  (:gen-class))

(defn wait-for-close
  []
  (let [promise (promise)]
    (immutant.util/at-exit #(deliver promise "please shutdown"))
    @promise))

(defn -main [& args]
  (web/run (fn [req] {:status 200 :body "hi"})
    )
  (future
    (Thread/sleep 5000)
    (println "Stopping")
    (web/stop))
  (wait-for-close)
  (println "done"))

and it doesn't exit after printing "Stopping". I don't see "done"

So maybe in my case is working because I am also exiting the jvm

I haven't paid attention too much to that distinction until you told me

(ns exit.core
  (:require [immutant.web :as web])
  (:gen-class))

(defn wait-for-close
  []
  (let [promise (promise)]
    (immutant.util/at-exit #(do (deliver promise "please shutdown")
                                (println "AT-EXIT")))
    @promise))

(defn -main [& args]
  (web/run (fn [req] {:status 200 :body "hi"})
    )
  (future
    (Thread/sleep 5000)
    (println "Stopping")
    ;;(web/stop)
    (immutant.util/reset))
  (wait-for-close)
  (println "done"))

well, I see "Stopping AT-EXIT done", but the JVM doesn't exit

so there are still non-daemon threads running somewhere

ah, it's likely the agent threadpool

let me (shutdown-agents) to see

Yes I have to do shutdown-agents as well

yeah, that does the trick. I just (shutdown-agents) after (wait-for-close)

immutant.util/reset is designed for repl use, and basically stops all of the running Immutant services, and triggers all the at-exit fns

Great good to know

so this will work once you add in immutant messaging, caching, etc.

Does it release resources as well? In a reloaded workflow this is important as well...

it should shut down all the various thread pools that any service starts, so you should be good

if you see a leak, that's a bug we should fix

I mean don't prevent the GC of pools and friends

Great ok

we use that in our testing, and haven't noticed any leaks

Awesome

but we shouldn't be holding any hard references after reset

Tnx a lot

Could not locate immutang/...

immutang!

it's a merging of wu tang clan and immutant

or maybe powdered orange drink

i was thinking the drink

I'm always thinking about drink