async-refresh: Package implementing core logic for refreshing of expiring data.

[ bsd3, control, library ] [ Propose Tags ]

This package can be used for refreshing of expiring data according to a user-provided action. Using callbacks, the user can decide how she or he would like to be informed about data refreshing.


[Skip to Readme]

Modules

[Index]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.7, 0.2.0, 0.2.0.2, 0.3.0.0
Dependencies base (>=4.7 && <5), formatting, lifted-async, microlens, microlens-th, monad-logger, safe-exceptions, stm, text, unliftio, unliftio-core [details]
License BSD-3-Clause
Copyright (c) 2017, 2018 Moritz Clasmeier
Author Moritz Clasmeier
Maintainer mtesseract@silverratio.net
Category Control
Home page https://github.com/mtesseract/async-refresh
Source repo head: git clone https://github.com/mtesseract/async-refresh
Uploaded by mtesseract at 2018-03-20T21:54:23Z
Distributions LTSHaskell:0.3.0.0, NixOS:0.3.0.0, Stackage:0.3.0.0
Reverse Dependencies 1 direct, 1 indirect [details]
Downloads 3319 total (20 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2018-03-20 [all 1 reports]

Readme for async-refresh-0.3.0.0

[back to package description]

async-refresh Hackage version Stackage version Build Status

About

This is Haskell library implementing the logic for refreshing of expiring data according to user-provided actions.

Usage

  • Create a new configuration using newAsyncRefreshConf, providing the action to be used for data refreshing.

  • Adjust the configuration using the asyncRefreshConfSet* functions, in particular using asyncRefreshConfSetCallback.

  • Use newAsyncRefresh to initiate a new thread managing the asynchronous refreshing.

Example

The following IO action produces a TVar which is updated every ten seconds to contain the current time (wrapped in an Either SomeException, because refreshing may fail).

periodicTimeUpdater :: IO (TVar (Either SomeException UTCTime))
periodicTimeUpdater = runStderrLoggingT $ do
  timeStore <- liftIO $ newTVarIO (Left (toException NotFound))
  let conf = newAsyncRefreshConf (RefreshResult <$> liftIO getCurrentTime <*> pure Nothing)
        & asyncRefreshConfSetLabel "CurrentTime updated every 10 seconds"
        & asyncRefreshConfSetDefaultInterval (10 * 10^3)
        & asyncRefreshConfSetCallback (liftIO . atomically . writeTVar timeStore . fmap refreshResult)
  _ <- newAsyncRefresh conf
  return timeStore