Add more safety around CancellationToken usage

This commit is contained in:
Dean Herbert 2022-01-29 12:18:34 +09:00
parent d0b74a91fb
commit 6f54f8ad78

View File

@ -3,11 +3,13 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using JetBrains.Annotations; using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Development;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Colour;
@ -189,6 +191,8 @@ namespace osu.Game.Online.Leaderboards
private void refetchScores() private void refetchScores()
{ {
Debug.Assert(ThreadSafety.IsUpdateThread);
Reset(); Reset();
PlaceholderState = PlaceholderState.Retrieving; PlaceholderState = PlaceholderState.Retrieving;
@ -215,10 +219,8 @@ namespace osu.Game.Online.Leaderboards
private void cancelPendingWork() private void cancelPendingWork()
{ {
currentFetchCancellationSource?.Cancel(); currentFetchCancellationSource?.Cancel();
currentFetchCancellationSource = null; currentScoresAsyncLoadCancellationSource?.Cancel();
fetchScoresRequest?.Cancel(); fetchScoresRequest?.Cancel();
fetchScoresRequest = null;
} }
#region Placeholder handling #region Placeholder handling
@ -280,7 +282,6 @@ namespace osu.Game.Online.Leaderboards
private void updateScoresDrawables() private void updateScoresDrawables()
{ {
currentScoresAsyncLoadCancellationSource?.Cancel(); currentScoresAsyncLoadCancellationSource?.Cancel();
currentScoresAsyncLoadCancellationSource = new CancellationTokenSource();
scoreFlowContainer? scoreFlowContainer?
.FadeOut(fade_duration, Easing.OutQuint) .FadeOut(fade_duration, Easing.OutQuint)
@ -319,7 +320,7 @@ namespace osu.Game.Online.Leaderboards
scrollContainer.ScrollToStart(false); scrollContainer.ScrollToStart(false);
loading.Hide(); loading.Hide();
}, currentScoresAsyncLoadCancellationSource.Token); }, (currentScoresAsyncLoadCancellationSource = new CancellationTokenSource()).Token);
} }
private void replacePlaceholder(Placeholder placeholder) private void replacePlaceholder(Placeholder placeholder)