Copyright | (c) Alexey Radkov 2023-2024 |
---|---|
License | BSD-style |
Maintainer | alexey.radkov@gmail.com |
Stability | stable |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Synopsis
- voidHandler :: IO a -> IO ByteString
- voidHandler' :: IO a -> Bool -> IO ByteString
- voidService :: a -> Bool -> IO ByteString
- module NgxExport.Tools.SplitService
Combinators of effectful actions
A set of functions to combine effectful actions for building handlers and services tuned for special purposes.
Exported functions
:: IO a | Target computation |
-> IO ByteString |
Runs an effectful computation and then returns an empty ByteString
.
This function saves printing the final return L.empty
action in handlers
that return unused or empty ByteString
.
For example, service signalUpconf being used as an update callback in
type Upconf = [Text] signalUpconf :: Upconf ->NgxExportService
signalUpconf upconf = const $ do mapConcurrently_ getUrl upconf return L.emptyngxExportSimpleServiceTyped
'signalUpconf ''Upconf $PersistentService
Nothing
returns an empty bytestring which is not used in a meaningful way, therefore it can be rewritten as
signalUpconf :: Upconf -> NgxExportService
signalUpconf = const . voidHandler . mapConcurrently_ getUrl
which helps to focus better on the computation itself.
Since: 1.2.0
:: IO a | Target computation |
-> Bool | Ignored boolean value |
-> IO ByteString |
Runs an effectful computation and then returns an empty ByteString
.
The same as voidHandler
except it accepts an additional boolean value
which is ignored. Implemented as
voidHandler' = const . voidHandler
This can be useful in declarations of services that accept a boolean flag
which marks whether the service is running for the first time. This flag is
often ignored though, in which case using voidHandler'
can simplify code.
For instance, service signalUpconf from the example for voidHandler
can
be further simplified as
signalUpconf :: Upconf -> NgxExportService
signalUpconf = voidHandler' . mapConcurrently_ getUrl
Since: 1.2.1
:: a | Ignored configuration |
-> Bool | Ignored boolean value |
-> IO ByteString |
A void service which does nothing and returns an empty ByteString
.
This can be useful for loading global data from the Nginx configuration in a more concise and declarative way.
For example, if data Conf in
newtype Conf = Conf Int deriving (Read, Show) testLoadConf :: Conf ->NgxExportService
testLoadConf = voidServicengxExportSimpleServiceTyped
'testLoadConf ''ConfSingleShotService
gets loaded by service testLoadConf from the Nginx configuration, then it
can be accessed in the Haskell code via IORef
data storage
storage_Conf_testLoadConf.
Since: 1.2.3
Split services
module NgxExport.Tools.SplitService