From 3c12957215c8de3bfb188b38090a0d63b0f06d43 Mon Sep 17 00:00:00 2001 From: SongKJ00 Date: Tue, 28 Nov 2023 17:24:19 +0900 Subject: [PATCH] use vthread --- src/superlifter/core.cljc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/superlifter/core.cljc b/src/superlifter/core.cljc index 73b58ba..04140f6 100644 --- a/src/superlifter/core.cljc +++ b/src/superlifter/core.cljc @@ -124,12 +124,15 @@ (defmethod start-trigger! :interval [_ bucket-id opts] (let [start-fn #?(:clj (fn [context] - (let [watcher (future (loop [] - (Thread/sleep (:interval opts)) - (fetch-all-handling-errors! context bucket-id) - (recur)))] + (let [continue? (atom true) + _watcher (prom/create (fn [resolve _reject] + (while @continue? + (Thread/sleep (:inverval opts)) + (fetch-all-handling-errors! context bucket-id)) + (resolve true)) + :vthread)] ;; return a function to stop the watcher - #(future-cancel watcher))) + #(reset! continue? false))) :cljs (fn [context] (let [watcher (js/setInterval #(fetch-all-handling-errors! context bucket-id)