module System.Session where
import Control.Concurrent.Session
import System.IO
lineSessionRaw
= newLabel ~>>= \l ->
l .= select ( (send string ~>> jump l) ~|~
end ~|~ BLNil
) ~>>
sreturn l
where
string = undefined::String
makeLineOutputChannel hdl lineSessionFragment = fork lineSessionFragment notDual nil child
where
child parentCh _ = withChannel parentCh f
where
f = soffer ( (srecv ~>>= sliftIO . hPutStrLn hdl ~>> f)
~||~
(sreturn ())
~||~ OfferImplsNil
)
makeLineInputChannel hdl lineSessionFragment = fork lineSessionFragment dual nil child
where
child parentCh _ = withChannel parentCh f
where
f = sliftIO (hIsClosed hdl) ~>>= \closed ->
if closed
then sselect (D1 E)
else sselect (D0 E) ~>>
sliftIO (hGetLine hdl) ~>>= \line ->
ssend line ~>>
f
stdoutLineOutputChannel = makeLineOutputChannel stdout
stdinLineInputChannel = makeLineInputChannel stdin