title: Difference between await for and listen in Dart
body: <p>I am trying to create a web server stream.  Here is the code:</p>
  
  <pre><code>import 'dart:io';
  
  main() async {
    HttpServer requestServer = await HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, 8000);
  
  requestServer.listen((request) {   //comment out this or the await for to work
    request.response
      ..write("This is a listen stream")
      ..close();
  });
  
    await for (HttpRequest request in requestServer) {
    request.response
      ..write("This is an await for stream")
      ..close();
    }
  }
  </code></pre>
  
  <p>What is the difference between listen and await for?  They both do not work at the same time.  You need to comment out one or the other to work, but there doesn't seem to be a difference in function here.  Are there circumstances where there is a difference, and when should you use one over the other?</p>