 (declare execute! schedule*)
 
 (defn- tick!
-  "This function is ran periodically, and at each tick it executes
-   events for which `currentTime` is included in their tolerance interval."
-  [clock]
-  (let [{:keys [events]} @clock
+  "This function is run constantly, and at each tick it executes events for
+   which `currentTime` is included in their tolerance interval."
+  [clock-atom]
+  (let [{:keys [events] :as clock} @clock-atom
         current-time (current-time clock)
         execute-now? #(<= (:earliest-time %) current-time)
-        now (take-while execute-now? events)]
-    (doseq [event now] (execute! event))
-    (swap! clock assoc :events (drop-while execute-now? (:events @clock))
-                       :current-time current-time)))
+        events-due   (take-while execute-now? events)]
+    (doseq [event events-due] (execute! event))
+    (when (seq events-due)
+      (swap! clock-atom update :events #(drop-while execute-now? %)))))
 
 (defn- index-by-time
   "Does a binary search to find the index of the first event whose deadline is

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defn set-timeout!
  "Schedules `f` after `delay` milliseconds. Returns the event.

   `opts` may contain :tolerance-early and :tolerance-late for optionally
   overriding the clock's timing window for events."
  [clock-atom f delay & {:as opts}]
  (create-event! clock-atom f (absolute-time @clock-atom delay) opts))

(defn callback-at-time!
  "Schedules `f` to run before `deadline`. Returns the event.


(defn clock
  [& {:as attrs}]
  (let [ctx        (swap! audio-context #(or % (new-audio-context)))
        id         (gensym "clock")
        clock      (merge default-options
