AsyncLazy anonymous function converted to a void returning delegate cannot return a value

浪子不回头ぞ 提交于 2021-01-07 02:17:56

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!