0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-20 13:55:34 -05:00

💄 Improve code of vertx timers ns.

This commit is contained in:
Andrey Antukh 2020-01-25 17:21:51 +01:00
parent e4c9d29b69
commit 9bcb91ceae

View file

@ -58,19 +58,19 @@
state (atom nil) state (atom nil)
taskfn (fn wrapped-task [] taskfn (fn wrapped-task []
(-> (p/do! ((::fn opts) opts)) (-> (p/do! ((::fn opts) opts))
(p/catch' (constantly nil)) ; explicitly ignore all errors (p/catch' (constantly nil)) ; explicitly ignore all errors
(p/then' (fn [_] ; the user needs to catch errors (p/then' (fn [_] ; the user needs to catch errors
(when repeat (if repeat
(let [tid (schedule-once! vsm delay wrapped-task)] (let [tid (schedule-once! vsm delay wrapped-task)]
(reset! state tid) (reset! state tid)
nil)))))) nil))
tid (schedule-once! vsm delay taskfn)] (do
(reset! state tid) (reset! state nil)
nil)))))
tid (reset! state (schedule-once! vsm delay taskfn))]
(reify (reify
java.lang.AutoCloseable java.lang.AutoCloseable
(close [this] (close [this]
(locking this (when (compare-and-set! state tid nil)
(when-let [timer-id (deref state)] (.cancelTimer system tid))))))
(.cancelTimer system timer-id)
(reset! state nil)))))))