Trying to figure out best practices to handle repeated actions in Haskell using Control.Concurrent.Timer
. Can't find good examples.
Suppose I have repeated action that must be done in application. Say it's fetching data from some webpage.
import Control.Concurrent.Suspend.Lifted
import Control.Concurrent.Timer
main :: IO ()
main = do
url <- fetchUrl :: IO Url
doSomethingWithUrl url
and I would like url to be fetched repeatly inside main so the data is always fresh. How could it be done?
forever $ threadDelay time >> forkIO (fetchUrl >>= doSomethingWithUrl)
. On the other hand, if doSomething is async then you'll want some mutable memory that fetch updates and doSomething reads.scotty $ do ...
) so i guess it's async. The data consumed after fetch.fetchUrl
which is API call of some service in my case has restriction on calls per IP per time.