public async Task Event_Throttler_TResult() { var et = new EventThrottler <int>(); Func <Task <int> > f1 = async() => { Debug.WriteLine("Starting 1"); await Task.Delay(50); Debug.WriteLine("Ending 1"); return(1); }; Func <Task <int> > f2 = async() => { Debug.WriteLine("Starting 2"); await Task.Delay(50); Debug.WriteLine("Ending 2"); return(2); }; Func <Task <int> > f3 = async() => { Debug.WriteLine("Starting 3"); await Task.Delay(50); Debug.WriteLine("Ending 3"); return(3); }; var t1 = et.RunAsync(f1, -1); var t2 = et.RunAsync(f2, -2); var t3 = et.RunAsync(f3, -3); Assert.AreEqual(await t1, 1); Assert.AreEqual(await t2, -2); Assert.AreEqual(await t3, 3); }
private async Task <bool> ThrottledGoBackAsync() { if (_isNavigating) { //Debug.Assert(false, "Navigation already in progress."); return(false); //throw new InvalidOperationException("Navigation already in progress."); } if (!this.CanGoBack) { //Debug.Assert(false, "GoBack() call failed. CanGoBack is false."); return(false); //throw new InvalidOperationException("GoBack() call failed. CanGoBack is false."); } if (!this.CanNavigate) { //Debug.Assert(false, "GoBack() call failed. CanNavigate is false."); return(false); //throw new InvalidOperationException("GoBack() call failed. CanNavigate is false."); } var backJournalEntry = this.BackStack.Peek(); return(await _navigationCallThrottler.RunAsync(() => this.NavigateCoreAsync( backJournalEntry.SourcePageType, backJournalEntry.Parameter, NavigationMode.Back), false)); }