Add cancellation support

This commit is contained in:
smoogipoo 2020-09-09 17:37:11 +09:00
parent 37a659b2af
commit 5cdc8d2e7b
1 changed files with 6 additions and 1 deletions

View File

@ -6,6 +6,7 @@
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;
using osu.Framework.Bindables;
@ -135,9 +136,13 @@ public TotalScoreBindable(ScoreInfo score, Func<BeatmapDifficultyManager> diffic
}
private IBindable<StarDifficulty> difficultyBindable;
private CancellationTokenSource difficultyCancellationSource;
private void onScoringModeChanged(ValueChangedEvent<ScoringMode> mode)
{
difficultyCancellationSource?.Cancel();
difficultyCancellationSource = null;
if (score.Beatmap == null)
{
Value = score.TotalScore;
@ -156,7 +161,7 @@ private void onScoringModeChanged(ValueChangedEvent<ScoringMode> mode)
}
// We can compute the max combo locally after the async beatmap difficulty computation.
difficultyBindable = difficulties().GetBindableDifficulty(score.Beatmap, score.Ruleset, score.Mods);
difficultyBindable = difficulties().GetBindableDifficulty(score.Beatmap, score.Ruleset, score.Mods, (difficultyCancellationSource = new CancellationTokenSource()).Token);
difficultyBindable.BindValueChanged(d => updateScore(d.NewValue.MaxCombo), true);
}
else