title: How to use MergeHub w/ Flow.mapAsync()
body: <p>I'm kind of confused how to use <code>MergeHub</code>.</p>
  
  <p>I'm designing a flow graph that uses <code>Flow.mapAsync()</code>, where the given function creates another flow graph, and then runs it with <code>Sink.ignore()</code>, and returns that <code>CompletionStage</code> as the value for <code>Flow.mapAsync()</code> to wait for. The nested flow will return elements via the <code>Sink</code> returned from materializing the <code>MergeHub</code>.</p>
  
  <p>The issue is that I need to provide the <code>Function</code> which starts the nested flow to <code>Flow.mapAsync()</code> when I'm creating the top-level flow graph, but that requires it to have access to the materialized value returned from materializing the result of <code>MergeHub.of()</code>. How do I get that materialized value before starting the flow graph?</p>
  
  <p>The only way I can see right now is to implement the <code>Function</code> to block until the <code>Sink</code> has been provided (after starting the top-level flow graph), but that seems pretty hacky.</p>
  
  <p>So, something like</p>
  
  <pre><code>class MapAsyncFunctor implements Function&lt;T, CompletionStage&lt;Done&gt;&gt; {...}
  MapAsyncFunctor mapAsyncFunctor = new MapAsyncFunctor();
  RunnableGraph&lt;Sink&lt;T&gt;&gt; graph = createGraph(mapAsyncFunctor);
  Sink&lt;T&gt; sink = materializer.materialize(graph);
  mapAsyncFunctor.setSink(sink); // Graph execution blocked in background in call to mapAsyncFunctor.apply() until this is done
  </code></pre>
  
  <hr>
  
  <p>Edit: I've created the following class</p>
  
  <pre><code>public final class Channel&lt;T&gt;
  {
      private final Sink&lt;T, NotUsed&gt; m_channelIn;
      private final Source&lt;T, NotUsed&gt; m_channelOut;
      private final UniqueKillSwitch m_killSwitch;
  
      public Channel(Class&lt;T&gt; in_class, Materializer in_materializer)
      {
          final Source&lt;T, Sink&lt;T, NotUsed&gt;&gt; source = MergeHub.of(in_class);
          final Sink&lt;T, Source&lt;T, NotUsed&gt;&gt; sink = BroadcastHub.of(in_class);
  
          final Pair&lt;Pair&lt;Sink&lt;T, NotUsed&gt;, UniqueKillSwitch&gt;, Source&lt;T, NotUsed&gt;&gt; matVals = in_materializer.materialize(source.viaMat(KillSwitches.single(), Keep.both()).toMat(sink, Keep.both()));
  
          m_channelIn = matVals.first().first();
          m_channelOut = matVals.second();
          m_killSwitch = matVals.first().second();
      }
  
      public Sink&lt;T, NotUsed&gt; in()
      {
          return m_channelIn;
      }
  
      public Source&lt;T, NotUsed&gt; out()
      {
          return m_channelOut;
      }
  
      public void close()
      {
          m_killSwitch.shutdown();
      }
  }
  </code></pre>
  
  <p>so that I can get a Source/Sink pair to use in building the graph. Is this a good idea? Will I 'leak' these channels if I don't explicitly close()
  them?</p>
  
  <p>I'll only ever need to use .out() once for my use-case.</p>