title: How to work with async* functions in Dart
body: <p>I am using flutter_bloc library.</p>
  
  <p>In the bloc, the <code>mapEventToState</code> method is an <code>async*</code> function which returns <code>Stream&lt;BlocState&gt;</code>. 
  From this function I am calling other <code>async*</code> functions like this <code>yield* _handleEvent(event)</code> </p>
  
  <p>In such method, I am calling some Future returns functions but in the Future <code>then()</code> function it wont let me call other yield* functions.</p>
  
  <p>Here is an example:</p>
  
  <pre><code>Stream&lt;BlocState&gt; mapEventToState(BlocEvent event) async*{
       yield* _handlesEvent(event); //This calls to worker method 
  }
  
  Stream&lt;BlocState&gt; _handleEvent(BlocEvent event) async* {
     _repository.getData(event.id).then((response) async* { //Calling Future returned function
           yield* _processResult(response); //This won't work
       }).catchError((e)  async* {
           yield* _handleError(e);  //This won't work either
       });
  
     Response response = await _repository.getData(event.id); //This do works but I want to use it like above, is it possible?
     yield* _processResult(response); //This do works
  }
  </code></pre>
  
  <p>The question is however, how to combine between Future and Stream in dart.
  I could use <code>await _repository.getData</code> which works. but then I won't catch the error.</p>