diff options
author | Paul Oliver <contact@pauloliver.dev> | 2024-12-29 17:05:34 +0000 |
---|---|---|
committer | Paul Oliver <contact@pauloliver.dev> | 2025-01-16 18:30:09 -0800 |
commit | cc639b06c7126fac7b445d8f778455620d7f8f50 (patch) | |
tree | a4c5c7c0b0a9cdb5bea0891e198003035065e57d /hsm-dummy-receiver/Main.hs |
Initial
Diffstat (limited to 'hsm-dummy-receiver/Main.hs')
-rw-r--r-- | hsm-dummy-receiver/Main.hs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/hsm-dummy-receiver/Main.hs b/hsm-dummy-receiver/Main.hs new file mode 100644 index 0000000..c0aa98a --- /dev/null +++ b/hsm-dummy-receiver/Main.hs @@ -0,0 +1,44 @@ +{-# LANGUAGE OverloadedRecordDot #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TemplateHaskell #-} + +import Data.Function ((&)) +import Data.Text (Text, pack) +import Effectful (Eff, (:>), runEff) +import Effectful.Log (Log, localDomain, logInfo_, runLog) +import Effectful.Reader.Static (runReader) +import Effectful.Resource (runResource) +import Hsm.Core.App (launch) +import Hsm.Core.Env (deriveFromYaml) +import Hsm.Core.Zmq.Client (receive, runClient) +import Streamly.Data.Fold qualified as S (drain) +import Streamly.Data.Stream qualified as S (Stream, fold, mapM) +import System.IO.Echo (withoutInputEcho) + +data Env = Env + { name :: Text + , subEps :: [Text] + , topics :: [Text] + } + +$(deriveFromYaml ''Env) + +handle :: + forall es. Log :> es + => S.Stream (Eff es) Int + -> Eff es () +handle = S.fold S.drain . S.mapM handler + where + handler :: Int -> Eff es () + handler p = + localDomain "receiver" $ logInfo_ $ "Received pulse #" <> pack (show p) + +main :: IO () +main = + launch @Env "dummy-receiver" withoutInputEcho $ \env logger level -> + (receive & handle) + & runClient @Env + & runLog env.name logger level + & runReader env + & runResource + & runEff |