title: Kotlin/anko multiple async tasks
body: <p>I'm looking for a simple way to start multiple tasks in parallel and wait for all of them to complete.</p>
  
  <p>Consider this c# example:
  </p>
  
  <pre><code>private static void Main(string[] args)
  {
      var urlList = new[] {"http://www.microsoft.com/", "http://www.google.com/", "http://www.apple.com/" };
      var result = GetHtml(urlList);
  }
  
  private static List&lt;string&gt; GetHtml(string[] urlList)
  {
      var tasks = new List&lt;Task&gt;();
      var output = new List&lt;string&gt;();
  
      foreach (var url in urlList)
      {
          var task = new Task(() =&gt;
          {
              var html = new WebClient().DownloadString(url);
              output.Add(html);
          });
  
          tasks.Add(task);
  
          //starts task in a separate thread (doesn't block anything)
          task.Start();
      }
  
      //waits for all tasks (running in parallel) to complete before exiting method
      Task.WaitAll(tasks.ToArray());
  
      return output;
  }
  </code></pre>
  
  <p>GetHtml method downloads multiple web-pages in parallel and returns a list of html strings.</p>
  
  <p>How can I achieve this using kotlin/anko?</p>
  
  <pre class="lang-java prettyprint-override"><code>private fun GetHtml(urlList: Array&lt;String&gt;): ArrayList&lt;String&gt; {
  
      val tasks = ArrayList&lt;Future&lt;Unit&gt;&gt;()
      val output = ArrayList&lt;String&gt;()
  
      for (url in urlList) {
          val task = async() {
              //some java-code that downloads html from &lt;url&gt;, doesn't matter for now
              output.add("html for $url")
          }
          tasks.add(task)
      }
  
      //this is NOT parallel execution
      for (task in tasks) {
          task.get()           
      }
  
      //tasks.getall() ?? 
  
      return output
  }
  </code></pre>