Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't know if it's any help, but I tried to implement Iain's suggestion and made a variant of <code>mergeSources'</code> that stops as soon as any of the channels does:</p> <pre><code>mergeSources' :: (MonadIO m, MonadBaseControl IO m) =&gt; [Source (ResourceT m) a] -- ^ The sources to merge. -&gt; Int -- ^ The bound of the intermediate channel. -&gt; ResourceT m (Source (ResourceT m) a) mergeSources' sx bound = do c &lt;- liftSTM $ newTBMChan bound mapM_ (\s -&gt; resourceForkIO $ s $$ chanSink c writeTBMChan closeTBMChan) sx return $ sourceTBMChan c </code></pre> <p>(This simple addition is available <a href="https://github.com/ppetr/stm-conduit/commits/master" rel="nofollow">here</a>).</p> <p>Some comments to your version of <code>mergeSources</code> (take them with a grain of salt, it can be I didn't understand something well):</p> <ul> <li>Using <code>...TMChan</code> instead of <code>...TBMChan</code> seems dangerous. If the writers are faster than the reader, your heap will blow. Looking at your diagram it seems that this can easily happen, if your TCP peer doesn't read data fast enough. So I'd definitely use <code>...TBMChan</code> with perhaps large but limited bound.</li> <li><p>You don't need the <code>MonadSTM m</code> constraint. All STM stuff is wrapped into <code>IO</code> with</p> <pre><code>liftSTM = liftIO . atomically </code></pre> <p>Maybe this will help you slightly when using <code>mergeSources'</code> in <code>serverApp</code>.</p></li> <li><p>Just a cosmetic issue, I found</p> <pre><code>liftSTM newTMChan &gt;&gt;= liftA2 (&gt;&gt;) (fsrc sx) retn </code></pre> <p>very hard to read due to its use of <code>liftA2</code> on the <code>(-&gt;) r</code> monad. I'd say</p> <pre><code>do c &lt;- liftSTM newTMChan fsrc sx c retn c </code></pre> <p>would be longer, but much easier to read.</p></li> </ul> <p>Could you perhaps create a self-contained project where it would be possible to play with <code>serverApp</code>?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload