title: How to implement interface method that returns Task<T>?
body: <p>I have an interface</p>
  
  <pre><code>interface IFoo
  {
    Task&lt;Bar&gt; CreateBarAsync();
  }
  </code></pre>
  
  <p>There are two methods to create <code>Bar</code>, one asynchronous and one synchronous. I want to provide an interface implementation for each of these two methods.</p>
  
  <p>For the asynchronous method, the implementation could look like this:</p>
  
  <pre><code>class Foo1 : IFoo
  {
    async Task&lt;Bar&gt; CreateBarAsync()
    {
      return await AsynchronousBarCreatorAsync();
    }
  }
  </code></pre>
  
  <p>But HOW should I implement the class <code>Foo2</code> that uses the <em>synchronous</em> method to create <code>Bar</code>?</p>
  
  <p>I <em>could</em> implement the method to run synchronously:</p>
  
  <pre><code>  async Task&lt;Bar&gt; CreateBarAsync()
    {
      return SynchronousBarCreator();
    }
  </code></pre>
  
  <p>The compiler will then warn against using <code>async</code> in the method signature:</p>
  
  <blockquote>
    <p>This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.</p>
  </blockquote>
  
  <p>Or, I <em>could</em> implement the method to explicitly return <code>Task&lt;Bar&gt;</code>. In my opinion the code will then look less readable:</p>
  
  <pre><code>  Task&lt;Bar&gt; CreateBarAsync()
    {
      return Task.Run(() =&gt; SynchronousBarCreator());
    }
  </code></pre>
  
  <p>From a performance point of view, I suppose both approaches have about the same overhead, or? </p>
  
  <p>Which approach should I choose; implement the <code>async</code> method synchronously or explicitly wrap the synchronous method call in a <code>Task</code>?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>The project I am working on is really a .NET 4 project with <em>async</em> / <em>await</em> extensions from the <a href="http://www.nuget.org/packages/Microsoft.Bcl.Async/">Microsoft Async</a> NuGet package. On .NET 4, <code>Task.Run</code> can then be replaced with <code>TaskEx.Run</code>. I consciously used the .NET 4.5 method in the example above in the hope of making the primary question more clear.</p>