mirror of https://github.com/status-im/timbre.git
[#141] Use java.util.concurrent.ExecutorService/submit instead of `future` (@ryfow)
(future) starts the agent threadpool, which slows down shutdown unless (shutdown-agents) is called.
This commit is contained in:
parent
ffe66948c6
commit
d59d902611
|
@ -563,13 +563,20 @@
|
|||
|
||||
#+clj
|
||||
(def get-hostname
|
||||
;; Note that this triggers slow shutdown, Ref. http://goo.gl/5hx9oK:
|
||||
(enc/memoize* (enc/ms :mins 1)
|
||||
(fn []
|
||||
(let [f_ (future ; Android doesn't like this on the main thread
|
||||
;; Android doesn't like this on the main thread
|
||||
;; `future` starts the agent threadpool so we use
|
||||
;; java.util.concurrent.
|
||||
(let [executor (java.util.concurrent.Executors/newSingleThreadExecutor)
|
||||
f_ (.submit executor
|
||||
^java.util.concurrent.Callable
|
||||
(fn []
|
||||
(try (.. java.net.InetAddress getLocalHost getHostName)
|
||||
(catch java.net.UnknownHostException _ "UnknownHost")))]
|
||||
(deref f_ 5000 "UnknownHost")))))
|
||||
(catch java.net.UnknownHostException _ "UnknownHost"))))]
|
||||
(try
|
||||
(deref f_ 5000 "UnknownHost")
|
||||
(finally (.shutdown executor)))))))
|
||||
|
||||
(comment (get-hostname))
|
||||
|
||||
|
|
Loading…
Reference in New Issue