aleph

valerauko 2018-12-05T13:59:32.020800Z

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

hugo 2018-12-05T14:45:48.022100Z

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)))

valerauko 2018-12-05T14:48:56.022600Z

awesome! just what i was looking for!

valerauko 2018-12-05T14:48:58.022800Z

thanks a lot!

hugo 2018-12-05T14:49:11.023Z

No worries 🙂