 
 ;; acq-engine
 
+
+(defn interruptible-sleep [time-ms]
+  (let [sleepy (CountDownLatch. 1)]
+    (swap! state assoc :sleepy sleepy)
+    (.await sleepy time-ms TimeUnit/MILLISECONDS)))
+
 (defn acq-sleep [interval-ms]
   (let [target-time (+ (@state :last-wake-time) interval-ms)
         sleep-time (- target-time (clock-ms))]
     (log-cmd (@state :last-wake-time))
     (when (pos? sleep-time)
-      (Thread/sleep sleep-time)
+      (interruptible-sleep sleep-time)
       (swap! state assoc :last-wake-time target-time))))
 
 (declare device-agents)

           [org.micromanager.navigation MultiStagePosition StagePosition]
           [mmcorej TaggedImage Configuration]
           [java.util.prefs Preferences]
           [org.micromanager.utils ChannelSpec GentleLinkedBlockingQueue MDUtils]
           [org.json JSONObject]
           [java.util Date UUID]

  
(defn -stop [this]
  (log "stop requested!")
  (let [state (.state this)]
    (swap! state assoc :stop true)
    (do-when #(.countDown %) (:sleepy @state))
    (log @state)))
  
(defn -isRunning [this]
  (:running @(.state this)))	
