问题
I am trying to call a ASP.NET MVC Action Result concurrently 11 times which is throwing few errors. To address that found a solution for similar issue poster over here https://stackoverflow.com/a/38636016/942855
Followed same answer using https://github.com/StephenCleary/AsyncEx/wiki/AsyncLazy
Here is my code
private readonly ConcurrentDictionary<GcrModelFull,
AsyncLazy<List<Airport>>> CachedProximityAirports;
public Task<List<Airport>> GcrAsync(GcrModelFull model)
{
var lazy = CachedProximityAirports.GetOrAdd(model, x =>
new AsyncLazy<List<Airport>>(() => Task.Run(() =>
{
try
{
return MyGcr(x.DepartureTimeOffset, x.Legs,
x.DepartureTimezoneInfo, x.OperatingUser, x.RequestEntity);
}
catch (Exception e)
{
//deal with errors
throw;
}
}, AsyncLazyFlags.RetryOnFailure | AsyncLazyFlags.ExecuteOnCallingThread)));
return lazy.Task;
}
I am using ASp.NET MVC on .NET CORE and Nito.AsyncEx.Coordination
Its complaining on my return
Anonymous function converted to a void returning delegate cannot return a value
Internal calling method signature is as below
private Task<List<Airport>> MyGcr(DateTimeOffset departureTimeOffset, List<RouteLeg> legs,
TimeZoneInfo departureTimezoneInfo,
User operatingUser, string requestEntity)
{
// some code
return Task.FromResult(listOfAirportData);
}
Update: It is still an issue if I replace
return MyGcr(x.DepartureTimeOffset, x.Legs,
x.DepartureTimezoneInfo, x.OperatingUser, x.RequestEntity);
with
return null;
So internal calling method has no impact on this error.
Update: Comment from @stephen helped to resolve the compile time issues, but main problem still exists. Want to call this method 11 time at a time asynchronously from JS
Any help on how to overcome this error is appreciated.
来源:https://stackoverflow.com/questions/64993808/asynclazy-anonymous-function-converted-to-a-void-returning-delegate-cannot-retur