From 8327ad5a5ae0394a0ec96990d970890733be8ae8 Mon Sep 17 00:00:00 2001 From: rcmerci Date: Wed, 11 Dec 2024 17:45:57 +0800 Subject: [PATCH] refactor: simplify by c.m/run-background-task --- src/main/frontend/worker/rtc/core.cljs | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/main/frontend/worker/rtc/core.cljs b/src/main/frontend/worker/rtc/core.cljs index e1890b2e7d3..3db4c33c671 100644 --- a/src/main/frontend/worker/rtc/core.cljs +++ b/src/main/frontend/worker/rtc/core.cljs @@ -387,22 +387,12 @@ ;;; ================ API (ends) ================ ;;; subscribe state ;;; +(c.m/run-background-task + :subscribe-state + (m/reduce + (fn [_ v] (worker-util/post-message :rtc-sync-state v)) + create-get-state-flow)) -(defonce ^:private *last-subscribe-canceler (atom nil)) -(defn- subscribe-state - [] - (when-let [canceler @*last-subscribe-canceler] - (canceler) - (reset! *last-subscribe-canceler nil)) - (let [cancel (c.m/run-task - (m/reduce - (fn [_ v] (worker-util/post-message :rtc-sync-state v)) - create-get-state-flow) - :subscribe-state)] - (reset! *last-subscribe-canceler cancel) - nil)) - -(subscribe-state) (comment (do