Skip to content

Commit

Permalink
[nop] Refactor: use enc/get-hostname
Browse files Browse the repository at this point in the history
Encore's hostname implementation is faster (uses smarter caching).
  • Loading branch information
ptaoussanis committed Feb 23, 2024
1 parent ffac479 commit b28eded
Showing 1 changed file with 2 additions and 21 deletions.
23 changes: 2 additions & 21 deletions src/taoensso/timbre.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -325,27 +325,8 @@

(comment (get-timestamp default-timestamp-opts (enc/now-udt)))

#?(:clj
(do ; Hostname stuff
(defn get-?hostname "Returns live local hostname, or nil." []
(try (.getHostName (java.net.InetAddress/getLocalHost))
(catch java.net.UnknownHostException _ nil)))

(let [unknown "UnknownHost"]
(def get-hostname "Returns cached hostname string."
(enc/memoize (enc/ms :mins 1)
(fn []
(try
(let [p (promise)]
;; Android doesn't like hostname calls on the main thread.
;; Using `future` would start the Clojure agent threadpool though,
;; which can slow down application shutdown w/o a `(shutdown-agents)`
;; call.
(.start (Thread. (fn [] (deliver p (get-?hostname)))))
(or (deref p 5000 nil) unknown))
(catch Exception _ unknown))))))))

(comment (get-hostname))
#?(:clj (defn ^:no-doc get-?hostname "Returns uncached local hostname string, or nil." [] (enc/get-hostname nil)))
#?(:clj (defn get-hostname "Returns cached local hostname string." ^String [] (enc/get-hostname (enc/msecs :mins 1) 5000 "UnknownHost")))

#?(:clj
(defn ansi-color [color]
Expand Down

0 comments on commit b28eded

Please sign in to comment.