refactor is in progress
This commit is contained in:
parent
04300a161e
commit
61ec499c0e
3 changed files with 69 additions and 12 deletions
|
@ -1,10 +1,13 @@
|
|||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module Config(Configuration(..),defaultConfiguration,HttpConfiguration (..)) where
|
||||
module Config(Configuration(..),forkBackend,withConfigs,forkWithConfigs) where
|
||||
|
||||
import Toml (TomlCodec, (.=))
|
||||
import qualified Toml
|
||||
import System.IO
|
||||
import qualified Data.Text as T
|
||||
import Control.Concurrent.MVar
|
||||
import Control.Concurrent
|
||||
import WaiApp
|
||||
|
||||
-- this module should handle everything connected to our TOML config
|
||||
#if defined(HTTP_SUPPORT) || defined(HTTPS_SUPPORT)
|
||||
|
@ -134,3 +137,20 @@ configurationCodec = pure (Configuration ())
|
|||
#ifdef CGI_SUPPORT
|
||||
<*> Toml.list cgiConfigCodec "cgi" .= cgiConf
|
||||
#endif
|
||||
|
||||
forkWithConfigs :: (a -> IO ()) -> TomlCodec [a] -> FilePath -> IO [MVar ()]
|
||||
forkWithConfigs f = withConfigs (\conf -> forkBackend $ f conf)
|
||||
|
||||
withConfigs :: (a -> IO (MVar ())) -> TomlCodec [a] -> FilePath -> IO [MVar ()]
|
||||
withConfigs f codec configFile = do
|
||||
parseResult <- Toml.decodeFileEither codec configFile
|
||||
either
|
||||
(error "Logging not implemented")
|
||||
(mapM f)
|
||||
parseResult
|
||||
|
||||
forkBackend :: IO () -> IO (MVar ())
|
||||
forkBackend f = do
|
||||
mVar <- newEmptyMVar
|
||||
forkFinally f (const $ putMVar mVar ())
|
||||
return mVar
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue