title: How can I correctly yield from a stream that uses Futures/async/await?
body: <p>I've encountered a weird issue where if I yield* from my provider in my flutter app, the rest of the code in the function doesn't complete.</p>
  
  <p>I'm using the BLoC pattern, so my _mapEventToState function looks like this:</p>
  
  <pre><code>  Stream&lt;WizardState&gt; _mapJoiningCongregationToState(
        int identifier, int password) async* {
      _subscription?.cancel();
      _subscription= (_provider.doThings(
              id: identifier, password: password))
          .listen((progress) =&gt; {
                dispatch(Event(
                    progressMessage: progress.progressText))
              }, onError: (error){
                print(error);
              }, onDone: (){
                print('done joiining');
              });
    }
  </code></pre>
  
  <p>Then in the provider/service... this is the first attempt.</p>
  
  <pre><code>final StreamController&lt;Progress&gt; _progressStream = StreamController&lt;JoinCongregationProgress&gt;();
  
   @override
    Stream&lt;JoinCongregationProgress&gt; doThings(
        {int id, int password}) async* {
  
          await Future.delayed(Duration(seconds:2));
  _progressStream.add(JoinCongregationProgress(progressText: "kake1..."));
  await Future.delayed(Duration(seconds:2));
  _progressStream.add(JoinCongregationProgress(progressText: "kake5!!!..."));
  yield* _progressStream.stream;
  }
  </code></pre>
  
  <p>The yield statement returns, but only <em>after</em> both awaited functions have completed.  This makes complete sense to me, obviously I wouldn't expect the code to complete out of order and somehow run the yield* before waiting for the 'await's to complete.</p>
  
  <p>In order to "subscribe" to the progress of this service though, I need to yield the stream back up to the caller, to write updates on the UI etc.  In my mind, this is as simple as moving the yield* to before the first await.  Like this.</p>
  
  <pre><code> final StreamController&lt;Progress&gt; _progressStream = StreamController&lt;JoinCongregationProgress&gt;();
  
       @override
        Stream&lt;JoinCongregationProgress&gt; doThings(
            {int id, int password}) async* {
              yield* _progressStream.stream;
              await Future.delayed(Duration(seconds:2));
      _progressStream.add(JoinCongregationProgress(progressText: "kake1..."));
      await Future.delayed(Duration(seconds:2));
      _progressStream.add(JoinCongregationProgress(progressText: "kake5!!!..."));
  
      }
  </code></pre>
  
  <p>But, then setting breakpoints on the later _progressStream.add calls show that these never get called.  I'm stuck on this, any idea what it could be?  I know it has something to do with how I have mixed Futures and Streams.</p>