equal
deleted
inserted
replaced
4 ( -- * Channel conversions |
4 ( -- * Channel conversions |
5 inputToChan |
5 inputToChan |
6 , chanToInput |
6 , chanToInput |
7 , chanToOutput |
7 , chanToOutput |
8 , makeChanPipe |
8 , makeChanPipe |
|
9 , chanToPipe |
|
10 , dupStream |
9 ) where |
11 ) where |
10 |
12 |
11 |
13 |
12 ------------------------------------------------------------------------------ |
14 ------------------------------------------------------------------------------ |
13 import Control.Applicative ((<$>), (<*>)) |
15 import Control.Applicative ((<$>), (<*>)) |
14 import Control.Concurrent.Chan.Unagi (InChan, OutChan, newChan, |
16 import Control.Concurrent.Chan.Unagi (InChan, OutChan, dupChan, |
15 readChan, writeChan) |
17 newChan, readChan, writeChan) |
|
18 import Control.Monad ((>=>)) |
16 import Prelude hiding (read) |
19 import Prelude hiding (read) |
17 import System.IO.Streams.Internal (InputStream, OutputStream, |
20 import System.IO.Streams.Internal (InputStream, OutputStream, |
18 makeInputStream, |
21 makeInputStream, |
19 makeOutputStream, read) |
22 makeOutputStream, read) |
20 |
23 |
54 -- blocking calls, be sure to do so in different threads. |
57 -- blocking calls, be sure to do so in different threads. |
55 makeChanPipe :: IO (InputStream a, OutputStream a) |
58 makeChanPipe :: IO (InputStream a, OutputStream a) |
56 makeChanPipe = do |
59 makeChanPipe = do |
57 (inChan, outChan) <- newChan |
60 (inChan, outChan) <- newChan |
58 (,) <$> chanToInput outChan <*> chanToOutput inChan |
61 (,) <$> chanToInput outChan <*> chanToOutput inChan |
|
62 |
|
63 |
|
64 -------------------------------------------------------------------------------- |
|
65 -- | Create a new pair of streams form the given 'Chan'. Everything written |
|
66 -- to the 'OutputStream' will appear as-is on the 'InputStream'. |
|
67 -- |
|
68 -- Since reading from the 'InputStream' and writing to the 'OutputStream' are |
|
69 -- blocking calls, be sure to do so in different threads. |
|
70 chanToPipe :: (InChan (Maybe a), OutChan (Maybe a)) -> IO (InputStream a, OutputStream a) |
|
71 chanToPipe (inChan, outChan) = (,) <$> chanToInput outChan <*> chanToOutput inChan |
|
72 |
|
73 |
|
74 -------------------------------------------------------------------------------- |
|
75 -- | Create a new input stream duplicated from the 'InChan' |
|
76 -- |
|
77 dupStream :: InChan (Maybe a) -> IO (InputStream a) |
|
78 dupStream = dupChan >=> chanToInput |