title: How to combine Lwt filters?
body: <p>I am currently learning <a href="http://ocsigen.org/lwt/2.4.7/manual" rel="nofollow">Lwt</a>. I am interested into using asynchronous processes to replace some shell routines by OCaml routines.</p>
  
  <p>Let us take a look at a simplified first attempt, where a filter is created by combining two threads running <code>cat</code>:</p>
  
  <pre><code>let filter_cat ()=
    Lwt_process.pmap_lines ("cat", [| "cat" |])
  
  let filter_t () =
    Lwt_io.stdin
    |&gt; Lwt_io.read_lines
    |&gt; filter_cat ()
    |&gt; filter_cat ()
    |&gt; Lwt_io.write_lines Lwt_io.stdout
  
  let () =
    filter_t ()
    |&gt; Lwt_main.run
  </code></pre>
  
  <p>This filter somehow works but hangs up when its standard input closes instead of exiting.  If I remove one of the <code>filter_cat</code>, it works as expected.</p>
  
  <p>I am guessing that I do not compose these filters appropriately and therefore cannot <em>join</em> the two threads I am starting. What is the correct way to compose these filters, so that the program terminates after it reads <code>EOF</code> on <code>stdin</code>?</p>
  
  <hr>
  
  <p>You can find this program together with a <a href="https://github.com/michipili" rel="nofollow">BSD Owl</a> Makefile in a <a href="https://gist.github.com/michipili/28d2358978d9e3c4bcef" rel="nofollow">Github gist</a>.</p>