Safe Haskell | None |
---|---|
Language | Haskell2010 |
System.ZMQ4.Patterns.RequestReply
Contents
Synopsis
- class (Binary a, Binary b) => RequestReply a b | a -> b
- responder :: RequestReply a b => String -> (a -> IO b) -> IO ()
- request :: RequestReply a b => String -> a -> IO b
Type class
class (Binary a, Binary b) => RequestReply a b | a -> b Source #
A request-reply type class.
a
is the request type, b
is the response type.
Example:
>>>
{-# LANGUAGE DataKinds #-}
>>>
{-# LANGUAGE TypeApplications #-}
>>>
>>>
import Control.Concurrent.Async
>>>
import Data.Binary
>>>
>>>
data A = A deriving (Binary, Show)
>>>
data B = B deriving (Binary, Show)
>>>
>>>
instance RequestReply A B
>>>
>>>
reply :: A -> IO B
>>>
reply _ = return B
>>>
>>>
main :: IO ()
>>>
main = withAsync (responder "tcp://*:5000" reply) $ \_ ->
>>>
requester "tcp://127.0.0.1:5000" A >>= print
Server and client
Arguments
:: RequestReply a b | |
=> String | Address to bind to |
-> (a -> IO b) | Reply function |
-> IO () |
Start responding using the given type class.
See RequestReply
for an example.
Silently ignores a request when decoding fails
Arguments
:: RequestReply a b | |
=> String | Address of the REP socket |
-> a | The request |
-> IO b | The reply |
Request a reply.
See RequestReply
for an example.
Throws an error when the response cannot be decoded.