The async-refresh package

[Tags:bsd3, library, test]

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]

Properties

Versions 0.1.7, 0.2.0
Dependencies base (>=4.7 && <5), formatting, lens, lifted-async, monad-control, monad-logger, safe-exceptions, stm, text [details]
License BSD3
Copyright (c) 2017 Moritz Schulte
Author Moritz Schulte
Maintainer mtesseract@silverratio.net
Category Control
Home page https://github.com/mtesseract/async-refresh
Source repository head: git clone https://github.com/mtesseract/async-refresh
Uploaded Tue Apr 11 14:19:12 UTC 2017 by mtesseract
Distributions LTSHaskell:0.2.0, NixOS:0.2.0, Stackage:0.2.0, Tumbleweed:0.2.0
Downloads 101 total (7 in the last 30 days)
Votes
0 []
Status Docs not available [build log]
All reported builds failed as of 2017-04-11 [all 2 reports]
Hackage Matrix CI

Modules

  • Control
    • Concurrent
      • Async
        • Control.Concurrent.Async.Refresh

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Readme for async-refresh

Readme for async-refresh-0.2.0

async-refresh

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