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