File tree Expand file tree Collapse file tree 1 file changed +29
-1
lines changed
src/hyperfiddle/electric/impl Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Original file line number Diff line number Diff line change 172172
173173(def -stall-ms 2000 )
174174
175+ (def !stats (atom {:live 0 , :done 0 , :transfers 0 }))
176+
177+ (def gather-stats
178+ [:gather-stats nil
179+ (fn [_ evt]
180+ (swap! !stats
181+ (fn [stats]
182+ (case (:event evt)
183+ (:spawned ) (update stats :live inc)
184+ (:done ) (-> stats (update :done inc) (update :live dec))
185+ (:transferred ) (update stats :transfers inc)
186+ #_else stats))))])
187+
188+ #?(:cljs (defn format-stats [{:keys [live done transfers]}]
189+ (str " Live: " live " \n Done: " done " \n Transfers: " transfers)))
190+
191+ #?(:cljs
192+ (defn insert-stats! [!stats node]
193+ (m/observe
194+ (fn [!]
195+ (let [txt (.createTextNode js/document " " )]
196+ (! nil )
197+ (.appendChild node txt)
198+ (.setInterval js/window #(set! (.-textContent txt) (format-stats @!stats)) 1000 ))))))
199+
200+ ; ; circular dependency, inline at usage site
201+ ; ; (e/defn FlowStatsMonitor [] (e/client (dom/pre (e/input (insert-stats! !stats dom/node)))))
202+
175203(def uninitialized-checks [#_(log prn) step-cannot-throw done-cannot-throw cancel-cannot-throw init-cannot-throw
176204 step-after-done step-after-throw double-step double-transfer
177- done-twice step-in-exceptional-transfer
205+ done-twice step-in-exceptional-transfer #_gather-stats
178206 #_(flow-transfer-stalled -stall-ms println) ; clogs the clock, revisit after optimizations
179207 (flow-cancellation-stalled -stall-ms println)]) ; experimental, not protocol violations
180208(def initialized-checks (conj uninitialized-checks initialized))
You can’t perform that action at this time.
0 commit comments