Note that there are some explanatory texts on larger screens.

plurals
  1. POFusing conduits with multiple inputs
    primarykey
    data
    text
    <p>I am trying to create a conduit that can consume multiple input streams. I need to be able to await on one or the other of the input streams in no particular order (e.g., not alternating) making zip useless. There is nothing parallel or non-deterministic going on here: I await on one stream or the other. I want to be able to write code similar to the following (where <code>awaitA</code> and <code>awaitB</code> await on the first or second input stream respectively):</p> <pre><code>do _ &lt;- awaitA x &lt;- awaitA y &lt;- awaitB yield (x,y) _ &lt;- awaitB _ &lt;- awaitB y' &lt;- awaitB yield (x,y') </code></pre> <p>The best solution I have is to make the inner monad another conduit, e.g.</p> <pre><code>foo :: Sink i1 (ConduitM i2 o m) () </code></pre> <p>Which then allows</p> <pre><code>awaitA = await awaitB = lift await </code></pre> <p>And this mostly works. Unfortunately, this seems to make it very difficult to fuse to the inner conduit before the outer conduit is fully connected. The first thing I tried was:</p> <pre><code>fuseInner :: Monad m =&gt; Conduit i2' m i2 -&gt; Sink i1 (ConduitM i2 o m) () -&gt; Sink i1 (ConduitM i2' o m) () fuseInner x = transPipe (x =$=) </code></pre> <p>But this doesn't work, at least when <code>x</code> is stateful since <code>(x =$=)</code> is run multiple times, effectively restarting <code>x</code> each time.</p> <p>Is there any way to write fuseInner, short of breaking into the internals of conduit (which looks like it would be pretty messy)? Is there some better way to handle multiple input streams? Am I just way to far beyond what conduit was designed for?</p> <p>Thanks!</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.
 

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