- forever $ do
- catchIOError (connect_and_loop cfg) (report_error . show)
- thread_sleep 10 -- Wait 10s before attempting to reconnect.
+ -- Begin connecting to our feed hosts, starting with the first one.
+ round_robin cfg 0
+
+ where
+ -- | This is the top-level "loop forever" function. If an
+ -- exception is thrown, it will propagate up to this point, where
+ -- it will be logged and ignored in style.
+ --
+ -- Afterwards, we recurse (call ourself) again to loop more forevers.
+ --
+ round_robin :: Configuration -> Int -> IO ()
+ round_robin cfg feed_host_idx = do
+ let hosts = get_feed_hosts $ feed_hosts cfg
+ let host = hosts !! feed_host_idx
+ catchIOError (connect_and_loop cfg host) (log_error . show)
+ thread_sleep 10 -- Wait 10s before attempting to reconnect.
+ round_robin cfg $ (feed_host_idx + 1) `mod` (length hosts)