title: Equivalent of C# async main in F#
body: <p>I was wondering what would be the equivalent of the C# async <code>main</code> in F#. More to the point, is there a special way of consuming/using async methods from <code>main</code> in an F# program or is it just a matter of waiting for completion?</p>
  
  <p>To be more concrete, say we are using the .NET Core Generic Host. </p>
  
  <p>In a C# program, <code>main</code> might look like this:</p>
  
  <pre><code>class Program
  {
      static async Task Main(string[] args)
      {
           await new HostBuilder().Build().RunAsync();
      }
  }
  </code></pre>
  
  <p>In an F# program, my instinct would be to do something like this:</p>
  
  <pre><code>[&lt;EntryPoint&gt;]
  let main args =
      HostBuilder().Build.RunAsync().Wait()
  </code></pre>
  
  <p>...or...</p>
  
  <pre><code>[&lt;EntryPoint&gt;]
  let main args =
      HostBuilder().Build.RunAsync() |&gt; Async.AwaitTask |&gt; Async.RunSynchronously
  </code></pre>
  
  <p>...or...</p>
  
  <pre><code>[&lt;EntryPoint&gt;]
  let main args = 
      async {
          return HostBuilder().Build.RunAsync() |&gt; Async.AwaitTask
      } |&gt; Async.RunSynchronously
  </code></pre>
  
  <p>...or just avoid async...but that's no fun...</p>
  
  <pre><code>[&lt;EntryPoint&gt;]
  let main args =
      HostBuilder().Build.Run()
  </code></pre>
  
  <p>There are a few more formulations I could show but I think these make the point.</p>
  
  <p>I imagine that part of the answer lies in answering these other questions</p>
  
  <ol>
  <li>"what does it mean to run an async main method" and </li>
  <li>"what's the point of making main async?"</li>
  </ol>
  
  <p>Going by examples, async <code>main</code> seems mostly to be about making it possible for other places to call <code>main</code> in an async way (in those cases where <code>main</code> is not really "main", ie. unit testing, etc). </p>
  
  <p>In the case of F#, I imagine there are at least 2 things preventing one from just returning an Async computation from <code>main</code>:</p>
  
  <ol>
  <li>The EntryPointAttribute that enforces an int return type for status codes...right?</li>
  <li>The compiler probably is not prepared to handle the async computation as the exit value of the program...right?</li>
  </ol>