title: How to set a timeout on a Hystrix command in Clojure?
body: <p>I'm learning about Hystrix and Clojure and don't understand how to (properly) set a timeout on a Hystrix command in Clojure.</p>
  
  <p>I searched StackOverflow and the web more generally. I looked at Hystrix's Clojure wrapper source code (<a href="https://github.com/Netflix/Hystrix/blob/master/hystrix-contrib/hystrix-clj/src/main/clojure/com/netflix/hystrix/core.clj" rel="nofollow">https://github.com/Netflix/Hystrix/blob/master/hystrix-contrib/hystrix-clj/src/main/clojure/com/netflix/hystrix/core.clj</a>). There is a init-fn function parameter that looked promising, but the comments seem to suggest that this won't be a sustainable solution. But would this be a simple start?</p>
  
  <p>I have a ridiculously simple Hystrix command running in Clojure and would appreciate help in extending this to set, say, a 200ms timeout:</p>
  
  <pre><code>(ns hystrix-timeout.core
    (:require [clojure.string :as str])
    (:require [com.netflix.hystrix.core :as hystrix])
    (:gen-class))
  
  
  (defn my-primary [a]
    (if (= a true) (throw (Exception. "Primary failed")) (str "primary: " a)))
  
  (defn my-fallback [a]
    (str "fallback: " a))
  
  (hystrix/defcommand my-command
    {:hystrix/fallback-fn my-fallback}
    [a]
    (my-primary a))
  
  
  (defn -main
    "Executes a simple Hystrix command. Will use a timeout when I know how to do this in Clojure."
    [&amp; args]
  
    (println (my-command false))
    (println (my-command true))
  
    (System/exit 0)   ; Exit explicitly as Hystrix threads are still running.
  )
  </code></pre>
  
  <p>I've put my lein project up at <a href="https://github.com/oliverbaier/learning/tree/master/hystrix-timeout" rel="nofollow">https://github.com/oliverbaier/learning/tree/master/hystrix-timeout</a> in case this makes answering easier.</p>
  
  <p>Thanks a lot,
  Oliver</p>