Fork me on GitHub
#aleph
<
2018-12-05
>
vale13:12:32

could anyone recommend me a library for retrying (with exponential backoff) using deferred?

hybas314:12:48

Zach addressed this sort of in this reddit post: https://www.reddit.com/r/Clojure/comments/48lf1a/managing_websocket_stability_issues_with_aleph/ Fairly easy to extend his example with exponential backoff:

(defn reconnect-loop!
  [conn-generator]
  (let [loop! (fn this [timeout]
                (d/chain
                 (conn-generator)
                 (fn [conn]
                   (if conn
                     (s/on-closed conn this)
                     (do @(d/future (Thread/sleep (t/seconds timeout)))
                         (this (* timeout 2)))))))]
  (loop! 1)))

vale14:12:56

awesome! just what i was looking for!

vale14:12:58

thanks a lot!

hybas314:12:11

No worries 🙂