vigilance-0.1.0.0: src/Utils/Vigilance/Worker.hs
{-# LANGUAGE NoImplicitPrelude #-}
module Utils.Vigilance.Worker ( workForeverWith
, workForeverWithDelayed
, workForever) where
import ClassyPrelude
import Control.Concurrent (threadDelay)
workForeverWithDelayed :: Int -> (SomeException -> IO ()) -> IO () -> IO ()
workForeverWithDelayed d handler action = workForeverWith handler doAction
where doAction = action >> threadDelay microseconds
microseconds = d * 1000000
workForeverWith :: (SomeException -> IO ()) -> IO () -> IO ()
workForeverWith handler = forever . handleAny handler
-- eats errors
workForever :: IO () -> IO ()
workForever = workForeverWith (const $ return ())