Skip to content

Commit 9699095

Browse files
committed
Refactorings based on code review suggestions
1 parent d4613bb commit 9699095

File tree

2 files changed

+24
-27
lines changed

2 files changed

+24
-27
lines changed

src/CommunityToolkit.Maui.UnitTests/Mocks/MockDispatcher.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,9 @@ public bool Dispatch(Action action)
2222

2323
public bool DispatchDelayed(TimeSpan delay, Action action)
2424
{
25-
Task.Run(async () =>
26-
{
27-
await Task.Delay(delay);
28-
29-
action();
30-
});
25+
Thread.Sleep(delay);
26+
27+
action();
3128

3229
return true;
3330
}

src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -561,31 +561,31 @@ void HandlePopupClosed(object? sender, EventArgs e)
561561
cancellationTokenSource?.Cancel();
562562
}
563563

564-
void HandlePopupOpened(object? sender, EventArgs e)
564+
async void HandlePopupOpened(object? sender, EventArgs e)
565565
{
566-
cancellationTokenSource?.Cancel();
567-
566+
if (cancellationTokenSource is not null)
567+
{
568+
await cancellationTokenSource.CancelAsync();
569+
}
570+
568571
cancellationTokenSource = new CancellationTokenSource();
569-
572+
570573
Console.WriteLine($"{DateTime.Now:O} HandlePopupOpened {BindingContext.GetType().Name}");
571574

572-
Dispatcher.DispatchDelayed(
573-
DisplayDuration,
574-
async () =>
575-
{
576-
if (cancellationTokenSource?.IsCancellationRequested is true)
577-
{
578-
return;
579-
}
580-
581-
Console.WriteLine(
582-
$"{DateTime.Now:O} Closing {BindingContext.GetType().Name} - {Application.Current?.Windows[0].Page?.Navigation.ModalStack.Count}");
583-
584-
await CloseAsync(Result, cancellationTokenSource?.Token ?? CancellationToken.None);
585-
586-
Console.WriteLine(
587-
$"{DateTime.Now:O} Closed {BindingContext.GetType().Name} - {Application.Current?.Windows[0].Page?.Navigation.ModalStack.Count}");
588-
});
575+
await Task.Delay(DisplayDuration);
576+
577+
if (cancellationTokenSource?.IsCancellationRequested is true)
578+
{
579+
return;
580+
}
581+
582+
Console.WriteLine(
583+
$"{DateTime.Now:O} Closing {BindingContext.GetType().Name} - {Application.Current?.Windows[0].Page?.Navigation.ModalStack.Count}");
584+
585+
await CloseAsync(Result, cancellationTokenSource?.Token ?? CancellationToken.None);
586+
587+
Console.WriteLine(
588+
$"{DateTime.Now:O} Closed {BindingContext.GetType().Name} - {Application.Current?.Windows[0].Page?.Navigation.ModalStack.Count}");
589589
}
590590

591591
public object? Result { get; }

0 commit comments

Comments
 (0)