 ;;
 
 
+;; A map from event metadata keys to the corresponding "run later" functions
+(def later-fns
+  {:flush-dom do-later              ;; after next annimation frame
+   :yield     goog.async.nextTick}) ;; almost immediately
+
 (defprotocol IEventQueue
   (enqueue [this event])
 

  (-process-1st-event [this])
  (-run-next-tick [this])
  (-run-queue [this])
  (-pause-run [this])
  (-exception [this ex])
  (-begin-resume [this]))


        (if (zero? n)
          (-fsm-trigger this :finish-run nil)
          (let [event-v (peek queue)]
            (if-let [later-fn (some later-fns (keys (meta event-v)))]
              (-fsm-trigger this :pause-run later-fn)
              (do (-process-1st-event this)
                  (recur (dec n)))))))))

  (-pause-run
    [this later-fn]
    (later-fn #(-fsm-trigger this :begin-resume nil)))

  (-begin-resume
    [this]
