This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-08-16
Channels
- # announcements (3)
- # babashka (48)
- # beginners (35)
- # calva (3)
- # chlorine-clover (5)
- # clj-kondo (9)
- # cljdoc (20)
- # cljsrn (1)
- # clojure (55)
- # clojure-europe (33)
- # clojure-nl (3)
- # clojure-norway (6)
- # clojure-spec (7)
- # clojure-uk (27)
- # clojurescript (95)
- # closh (1)
- # conjure (1)
- # cursive (16)
- # datomic (30)
- # emacs (7)
- # honeysql (1)
- # hugsql (2)
- # introduce-yourself (2)
- # jobs (1)
- # lsp (30)
- # malli (22)
- # nbb (11)
- # news-and-articles (1)
- # off-topic (8)
- # pathom (21)
- # polylith (41)
- # portal (4)
- # practicalli (4)
- # protojure (1)
- # re-frame (14)
- # releases (1)
- # restql (1)
- # reveal (24)
- # sci (1)
- # sql (21)
- # vim (11)
- # xtdb (33)
i'm looking at retrying api calls, but i'd like to have the retries exponentially back off
what's the best way to dispatch an event after a pause?
js/setTimeout
?
seems like js/setTimeout
would most work for side effecting functions. but in the context of re-frame, i think the functions are pure...
> seems like `js/setTimeout` would most work for side effecting functions. but in the context of re-frame, i think the functions are pure...
then again, an api call is a side effect. so maybe js/setTimeout
would be fairly straightforward here.
we have an api call effect handler, i can just write another that accepts a delay and invoke setTimeout
yep, so what I would do is
(rf/reg-fx
::delayed-dispatch
(fn [{:keys [event delay]}]
(js/setTimeout #(rf/dispatch event) delay)))
(defn delayed-dispatch
[{:keys [event delay] :as args}]
[[::delayed-dispatch args]])
...
(defn your-http-fx
[args]
[[::http-effect args]]
...
(rf/reg-event-fx
::failed-call
(fn [...]
{:fx (delayed-dispatch [::make-call ...] ... delay ...)}))
(rf/reg-event-fx
::make-call
(fn [{:keys [db]} [_ delay]]
{:fx (your-http-fx ... :on-failure ::failed-call)}))
but this is a perfectly acceptable use of fx - waiting for a delay is something that can be considered an "outside subsystem"