module DialogueIO(Request(..), Response(..), IOError(..)
, Dialogue(..), SigAct(..) , dialogueToIO
) where
import Prelude hiding (IOError)
import P_IO_data
import DoRequest
import Control.Concurrent.Chan
dialogueToIO :: Dialogue -> IO ()
dialogueToIO :: Dialogue -> IO ()
dialogueToIO Dialogue
f =
do XCallState
st <- IO XCallState
initXCall
Chan Response
respchan <- IO (Chan Response)
forall a. IO (Chan a)
newChan
[Request]
reqs <- Dialogue
f Dialogue -> IO [Response] -> IO [Request]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` Chan Response -> IO [Response]
forall a. Chan a -> IO [a]
getChanContents Chan Response
respchan
let doReq :: Request -> IO ()
doReq Request
req = Chan Response -> Response -> IO ()
forall a. Chan a -> a -> IO ()
writeChan Chan Response
respchan (Response -> IO ()) -> IO Response -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< XCallState -> Request -> IO Response
doRequest XCallState
st Request
req
(Request -> IO ()) -> [Request] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Request -> IO ()
doReq [Request]
reqs