                  (let [grid (assoc grid :path {:distances distances
                                                :color-family :red})]
                    (set-maze-params! :grid (atom grid))
-                   (async/<! (async/timeout 0))
+                   (async/<! (sync-chan anim-chan))
                    (recur grid)))
                grid))))
 

(defui MazeDisplay
  static om/IQuery
  (query [this]
    '[{:maze [:grid :rows :columns :cell-size :algorithm :active]}])
  Object
  (componentDidMount [this]
    (println "componentDidMount called.")
    (let [{:keys [grid cell-size sync-chan] :as maze} (om/props this)
          c @thecanvas
          g (.getContext c "2d")]
      (image/image-grid g @grid cell-size)
      ; (go (when sync-chan (async/>! sync-chan true)))
      ))
  (componentDidUpdate [this prev-props prev-state]
    (println "componentDidUpdate called.")
    (let [{:keys [grid cell-size sync-chan] :as maze} (om/props this)
          c @thecanvas
          g (.getContext c "2d")]
      (image/image-grid g @grid cell-size)
      ; (go (when sync-chan (async/>! sync-chan true)))
      ))
  (render [this]
    (let [{:keys [grid rows columns algorithm cell-size active] :as maze} (om/props this)]

  {:app/algorithms (sort algs/algorithm-names)
   :app/analyses ["none" "distances" "path" "longest path"]
   :maze {:algorithm ""
          :rows      10
          :columns   10
          :cell-size 10
          :grid      nil
          :anim-chan (async/chan)

          :analysis  "none"
          :start-row 0
          :start-col 0
          :end-row   0
          :end-col   0

          :active    nil}})

(defn sync-chan [frame-chan]
  (if sync-by-frame
    frame-chan
    (async/timeout 0)))

(defn produce-distances-async [{:keys [start-row start-col anim-chan] :as maze-params} grid-key color-family maze]
  (let [prev-distances (:distances maze)
        [start-row start-col] (if prev-distances (:max-coord prev-distances) [start-row start-col])
        analysis-fn #(algs/distances-seq maze [start-row start-col])
