I'm assuming you want all your sinks to receive all values.
I'd suggest:
- Use
newBroadcastTMChan
to create a new channelControl.Concurrent.STM.TMChan
(stm-chans). - Use this channel to build a sink using
sinkTBMChan
fromData.Conduit.TMChan
(stm-conduit) for your main producer. - For each client use
dupTMChan
to create its own copy for reading. Start a new thread that will read this copy usingsourceTBMChan
. - Collect results from your threads.
- Be sure your clients can read the data as fast as they're produced, otherwise you can get heap overflow.
(I haven't tried it, let us know how it works.)
Update: One way how you could collect the results is to create a MVar
for each consumer thread. Each of them would putMVar
its result after it's finished. And your main thread would takeMVar
on all these MVar
s, thus waiting for every thread to finish. For example if vars
is a list of your MVar
s, the main thread would issue mapM takeMVar vars
to collect all the results.