Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use java.util.concurrent.ExecutorService/submit instead of future #141

Merged
merged 1 commit into from
Dec 15, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/taoensso/timbre.cljx
Original file line number Diff line number Diff line change
Expand Up @@ -546,13 +546,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
(try (.. java.net.InetAddress getLocalHost getHostName)
(catch java.net.UnknownHostException _ "UnknownHost")))]
(deref f_ 5000 "UnknownHost")))))
(fn []
;; 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"))))]
(try
(deref f_ 5000 "UnknownHost")
(finally (.shutdown executor)))))))

(comment (get-hostname))

Expand Down