[Haskell-cafe] question about conduit source
Alexander V Vershilov
alexander.vershilov at gmail.com
Tue Feb 28 17:04:47 CET 2012
Hello, cafe.
Is it possible to read data from different concurrent sources,
i.e. read data from source as soon as it become avaliable, e.g.
runResourceT $ (source1 stdin $= CL.map Left)
>=> (source2 handle $= CL.map Right)
$= application
$$ sink
where >=> - stands for concurrent combining of sources
It would be good if it can be sources of different types (handle or
STM channel, etc..).
Currently I've found no good way to handle with this situation,
except of using STM Channels for collecting data
source1 ---+ |
| sink | output sink
+---] Channel [-------> application----->]
| source
source2 ---+ |
From this point of view application takes concurent data, but this
implementation requires additional thread per data processing. Also
in many cases it will require run additional runResourceT (see later
example).
So if there any possible simplifications? Or ideas how to make (>=>)
operator.
Example:
So I've got next code in my network-conduit based application:
main :: IO ()
main = do
pool <- createDBPool "..." 10
let r = ServerInit pool
forkIO $ forever clientConsole --read channel list and send "Left"
flip runReaderT r $
runTCPServer (ServerSettings 3500 Nothing) (protoServer)
myServer src sink = do
ch <- liftIO $ atomically $ newTBMChan 16
initState <- lift $ ask
_ <- liftIO $ fork . (flip runReaderT initState) $
runResourceT $ src $= C.sequence decode
$= CL.map Right $$ sinkTBMChan ch
sourceTBMChan ch
$= process $= C.sequence encode $$ sinkHandle stdout
But in this situation I don't know if freeing of all resources are guaranteed,
because I'm running additional resourceT in main resourceT scope.
So can you advice is it possible to make concurrent sources now with currenly
implemented library?
If it's not possible but worth of implementing, so I can make that functions?
Is it correct to runResourceT inside another resourceT?
--
Best regards,
Alexander V Vershilov
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: Digital signature
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120228/ad373226/attachment.pgp>
More information about the Haskell-Cafe
mailing list