1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
module Main
( main
)
where
import Data.Aeson.TH (defaultOptions, deriveFromJSON, rejectUnknownFields)
import Data.Function ((&))
import Data.Text (Text, show)
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.Zmq (receive, runClient)
import Streamly.Data.Fold (drain)
import Streamly.Data.Stream (fold, mapM, repeatM)
import Prelude hiding (mapM, show)
data Env = Env
{ name :: Text
, subEps :: [Text]
, topics :: [Text]
}
$(deriveFromJSON defaultOptions {rejectUnknownFields = True} ''Env)
receiver :: Log :> es => Int -> Eff es ()
receiver =
localDomain "receiver"
. logInfo_
. mappend "Received pulse #"
. show
main :: IO ()
main =
launch @Env "dummy-receiver" $ \env logger level ->
(repeatM receive & mapM receiver & fold drain)
& runClient @Env
& runLog env.name logger level
& runReader env
& runResource
& runEff
|