             [hiccup.page :as hp]
             [hiccup.element :as he]
             [clojure.data.json :as json]
-            [clojure.core.async :as a :refer [alts!! chan <!! >!! timeout]])
+            [clojure.core.async :as a :refer [alts!! close! chan <!! >!! timeout]])
   (:use ring.server.standalone
         [ring.middleware file-info file])
   (:import de.prob.animator.command.CbcSolveCommand

(defn destroy []
  (doseq [_ (range instances)] (<!! @worker))
  (reset! worker nil)
  (println :destroy)
  (System/exit 0))





(defn solve [request]
  (let [ toc (timeout request-timeout)
        [solver c] (alts!! [@worker toc])]
    (if-not (= c toc)
      (close! toc)
      (let [result (solver request)]
        (>!! @worker solver)
        result)
