title: Convert async lambda expression to delegate type System.Func<T>?
body: <p>I have an async method inside a portable class library with this signature:</p>
  
  <pre><code>private async Task&lt;T&gt; _Fetch&lt;T&gt;(Uri uri)
  </code></pre>
  
  <p>It fetches a resource that is cast back as a concrete type T.</p>
  
  <p>I'm working with a 3rd party cache library (<a href="https://github.com/github/Akavache" rel="noreferrer">Akavache</a>) that requires a <code>Func&lt;T&gt;</code> as one of the parameters and have tried to do so in this manner:</p>
  
  <pre><code>await this.CacheProvider.GetOrCreateObject&lt;T&gt;(key,
      async () =&gt; await _Fetch&lt;T&gt;(uri), cacheExpiry);
  </code></pre>
  
  <p>This results in the error:</p>
  
  <blockquote>
    <p>Cannot convert async lambda expression to delegate type '<code>System.Func&lt;T&gt;</code>'. An async lambda expression may return <code>void</code>, <code>Task</code> or <code>Task&lt;T&gt;</code>, none of which are convertible to '<code>System.Func&lt;T&gt;</code>'.</p>
  </blockquote>
  
  <p>I've tried various permutations of <code>Func&lt;T&gt;</code> assignment without any luck, the only way I can get the code to work is to make the <code>Func&lt;T&gt;</code> blocking:</p>
  
  <pre><code>await this.CacheProvider.GetOrCreateObject&lt;T&gt;(key, 
      () =&gt; _Fetch&lt;T&gt;(uri).Result, cacheExpiry); 
  </code></pre>
  
  <p>which deadlocks my app.</p>
  
  <p>Any pointers on where I'm going astray?</p>