configurator / tests / TestReload.hs

{-# LANGUAGE OverloadedStrings #-}

import Control.Exception
import Control.Concurrent
import Data.Configurator
import Data.Configurator.Types
import qualified Data.ByteString.Lazy.Char8 as L
import System.Environment
import System.Directory
import Control.Monad
import System.IO

main = do
  args <- getArgs
  tmpDir <- getTemporaryDirectory
  temps <- forM args $ \arg -> do
           (p,h) <- openBinaryTempFile tmpDir "test.cfg"
           L.hPut h =<< L.readFile arg
           hClose h
           return p
  flip finally (mapM_ removeFile temps) $ do
    done <- newEmptyMVar
    let myConfig = autoConfig {
                     onError = \e -> hPutStrLn stderr $ "uh oh: " ++ show e
    (c,_) <- autoReload myConfig temps
    display c
    subscribe c "dongly" $ \n v -> putMVar done ()
    --threadDelay 1000000
    forM_ temps $ \t -> L.appendFile t "\ndongly = 1\n"
    takeMVar done
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.