microsoft / SmartHotel360-Mobile

SmartHotel360 Mobile

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Asnyc Usage

mzhukovs opened this issue · comments

Greetings, more of a question than an issue I suppose, but I see some places where navigation isn't awaited, and the usage of this AsyncCommand is a little puzzling to me. Would you mind explaining the rationale behind the differences in the following 2 cases?

In BookingCalendarViewModel:

        public ICommand NextCommand => new AsyncCommand(NextAsync);
        private Task NextAsync()
        {
            var navigationParameter = new Dictionary<string, object>
            {
                { "city", City },
                { "from", From },
                { "until", Until },
            };

            return NavigationService.NavigateToAsync<BookingHotelsViewModel>(navigationParameter);
        }

but in BookingsHotelViewModel:

        public ICommand HotelSelectedCommand => new Command<Models.Hotel>(OnSelectHotelAsync);
        private async void OnSelectHotelAsync(Models.Hotel item)
        {
            if (item != null)
            {
                var navigationParameter = new Dictionary<string, object>
                {
                    { "hotel", item },
                    { "from", From },
                    { "until", Until },
                };

                await NavigationService.NavigateToAsync<BookingHotelViewModel>(navigationParameter);
            }
        }

I think Eric Lippert summed up this answer quite well in a StackOverflow response he provided, so I'm linking to it in this reply. I've referred to his response a few times over the years to answer this question.

With regards to this variance, I'm adding @eiximenis here as this may have been an accidental inconsistency. If there's no specific rationale for one being a void and one being a Task, can we make the methodology consistent and change whichever one is NOT consistent with the other methods throughout the code?

Thanks!

Hi.
Inconsistent usage due to some refactoring I guess. We should return Task in all cases.

Another question - I see a lot of opportunity for using Stephen Cleary's NotifyTask in this project - was this considered? If so, what were the reasons against it? And any thoughts on this?

P.S. I want to say thanks to everyone that contributed to this and made it available - it has been a great learning tool for me, as I'm sure it has been for others as well