Clean up state loop
This commit is contained in:
parent
f496fb51e5
commit
dd5bf7a53a
1 changed files with 16 additions and 20 deletions
|
@ -59,27 +59,23 @@
|
||||||
(go (loop [shadow initial-shadow
|
(go (loop [shadow initial-shadow
|
||||||
states (sync/new-state @state)]
|
states (sync/new-state @state)]
|
||||||
(let [[v c] (a/alts! [new-states events] :priority true)]
|
(let [[v c] (a/alts! [new-states events] :priority true)]
|
||||||
(when v
|
(cond (nil? v) nil ;; drop out of loop
|
||||||
(cond (= c new-states)
|
(= c new-states)
|
||||||
(let [current (sync/get-current-state states)]
|
(do (when-not (= shadow v)
|
||||||
(when-not (= shadow v)
|
|
||||||
(>! >remote (diff-msg shadow v)))
|
(>! >remote (diff-msg shadow v)))
|
||||||
(recur shadow
|
(recur shadow (sync/add-history-state states v)))
|
||||||
(if (= v current)
|
(= c events)
|
||||||
states
|
(let [event (assoc v
|
||||||
(sync/add-history-state states v))))
|
:states states
|
||||||
(= c events)
|
:client? client?
|
||||||
(let [event (assoc v
|
:shadow shadow)
|
||||||
:states states
|
{:keys [new-states new-shadow out-event]} (handle-event event)]
|
||||||
:client? client?
|
(when (and new-states (not= states new-states))
|
||||||
:shadow shadow)
|
(let [new-state (sync/get-current-state new-states)]
|
||||||
{:keys [new-states new-shadow out-event]} (handle-event event)]
|
(reset! state new-state)))
|
||||||
(when (and new-states (not= states new-states))
|
(when out-event (a/put! >remote out-event))
|
||||||
(let [new-state (sync/get-current-state new-states)]
|
(recur (if new-shadow new-shadow shadow)
|
||||||
(reset! state new-state)))
|
(if new-states new-states states)))))))))
|
||||||
(when out-event (a/put! >remote out-event))
|
|
||||||
(recur (if new-shadow new-shadow shadow)
|
|
||||||
(if new-states new-states states))))))))))
|
|
||||||
|
|
||||||
(def make-server-agent (partial make-agent false))
|
(def make-server-agent (partial make-agent false))
|
||||||
(def make-client-agent (partial make-agent true))
|
(def make-client-agent (partial make-agent true))
|
||||||
|
|
Loading…
Reference in a new issue