zeromq4-patterns 0.2.0.0 → 0.3.0.0
raw patch · 3 files changed
+16/−17 lines, 3 filesdep −transformers
Dependencies removed: transformers
Files
- src/System/ZMQ4/Patterns/RequestReply.hs +9/−9
- test/Test/System/ZMQ4/Patterns/RequestReply.hs +6/−6
- zeromq4-patterns.cabal +1/−2
src/System/ZMQ4/Patterns/RequestReply.hs view
@@ -5,7 +5,7 @@ {-# LANGUAGE ScopedTypeVariables #-} module System.ZMQ4.Patterns.RequestReply ( -- * Type class- RequestReply(..)+ RequestReply -- * Server and client , responder@@ -16,7 +16,6 @@ import Control.Monad.IO.Class (liftIO) import Data.Binary-import Data.Proxy (Proxy) import qualified Data.ByteString.Lazy as BL import System.ZMQ4.Monadic@@ -36,15 +35,16 @@ -- >>> data A = A deriving (Binary, Show) -- >>> data B = B deriving (Binary, Show) -- >>>--- >>> instance RequestReply A B where--- >>> reply _ = B+-- >>> instance RequestReply A B -- >>>+-- >>> reply :: A -> IO B+-- >>> reply _ = return B+-- >>> -- >>> main :: IO ()--- >>> main = withAsync (responder @A Proxy "tcp://*:5000") $ \_ ->+-- >>> main = withAsync (responder "tcp://*:5000" reply) $ \_ -> -- >>> requester "tcp://127.0.0.1:5000" A >>= print -- class (Binary a, Binary b) => RequestReply a b | a -> b where- reply :: a -> IO b -- | Start responding using the given type class. --@@ -53,10 +53,10 @@ -- Silently ignores a request when decoding fails responder :: forall a b . RequestReply a b- => Proxy a -- ^ Proxy type of the request type- -> String -- ^ Address to bind to+ => String -- ^ Address to bind to+ -> (a -> IO b) -- ^ Reply function -> IO ()-responder _ addr = runZMQ $ do+responder addr reply = runZMQ $ do rep <- socket Rep bind rep addr
test/Test/System/ZMQ4/Patterns/RequestReply.hs view
@@ -1,6 +1,5 @@ {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE FunctionalDependencies #-}-{-# LANGUAGE TypeApplications #-} module Test.System.ZMQ4.Patterns.RequestReply (tests) where import Control.Concurrent.Async@@ -8,7 +7,6 @@ import Control.Monad (replicateM) import Data.Binary-import Data.Proxy import GHC.Generics (Generic) @@ -34,10 +32,12 @@ instance Binary Response -instance RequestReply Request Response where- reply ReqA = return RepA- reply ReqB = return RepB+instance RequestReply Request Response +reply :: Request -> IO Response+reply ReqA = return RepA+reply ReqB = return RepB+ newtype TestSetup = TestSetup [Request] deriving (Show) instance Arbitrary TestSetup where@@ -45,7 +45,7 @@ prop_server_client :: TestSetup -> Property prop_server_client (TestSetup reqs) = within (10*1000*1000) $ ioProperty $- withAsync (responder @Request Proxy addr) $ \_ ->+ withAsync (responder addr reply) $ \_ -> checkAll reqs where
zeromq4-patterns.cabal view
@@ -1,5 +1,5 @@ name: zeromq4-patterns-version: 0.2.0.0+version: 0.3.0.0 synopsis: Haskell implementation of several ZeroMQ patterns. description: Haskell implementation of several ZeroMQ patterns that you can find in the@@ -31,7 +31,6 @@ , bytestring , exceptions , stm- , transformers , zeromq4-haskell default-language: Haskell2010 ghc-options: -Wall