<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Mar 5, 2013 at 9:24 AM, Michael Snoyman <span dir="ltr">&lt;<a href="mailto:michael@snoyman.com" target="_blank">michael@snoyman.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>...<br><div>I&#39;m not sure if I entirely understand your use case, but in general it should be possible to have multiple Conduits running one after the other. Here&#39;s an example of restarting an accumulator after every multiple of 5:</div>



<div><br></div><div><a href="https://www.fpcomplete.com/user/snoyberg/random-code-snippets/multiple-conduits" target="_blank">https://www.fpcomplete.com/user/snoyberg/random-code-snippets/multiple-conduits</a><span class=""><font color="#888888"><br>

</font></span></div><br></div></blockquote><div><br></div><div>Neat.  I didn&#39;t think to do that with plain Conduits.  I did realize I could use a resumable conduit as a &quot;temporary filter&quot; (basically what your example does).  This suggests that a resumable conduit can be used in any consumer (Conduit or Sink), not just a sink.  Perhaps it can even be used in a producer, though different operators would be needed (+$= instead of =$+).<br>

<br></div><div>In my compression example, the incoming message sink needs to feed chunks of compressed data to a zlib conduit.  It can&#39;t just hand full control of the input to zlib; it has to decode messages, and only send CompressedData messages through zlib.  I need a resumable conduit for that.<br>

</div><div><br></div><div>Here&#39;s my current implementation of resumable conduits [1].  I don&#39;t know much about conduit finalizers; I mostly followed  &#39;connectResume&#39; and &#39;pipeL&#39;.<br><br></div><div>

The main wrinkle is that when the ResumableConduit receives an upstream terminator, it forwards it to the sink, rather than telling the conduit that the stream ended.  This allows the conduit to be reused.  Only when we finish the ResumableConduit () do we send it the stream terminator.<br>

<br></div><div>I&#39;ll continue toying with this.  It might be possible to factor out terminator forwarding, and generalize connectResume to support resumable sources, conduits, and sinks.<br><br>Thanks for the help,<br>

</div><div>-Joey<br></div><div><br> [1]: <a href="https://github.com/joeyadams/hs-resumable-conduit/blob/master/ResumableConduit.hs">https://github.com/joeyadams/hs-resumable-conduit/blob/master/ResumableConduit.hs</a><br>

</div></div></div></div>