mirror of
https://github.com/ppy/osu.git
synced 2024-12-13 08:32:57 +08:00
Store all linked cancellation tokens
This commit is contained in:
parent
1ff3b20a5e
commit
ff3cb6487d
@ -109,25 +109,42 @@ namespace osu.Game.Beatmaps
|
||||
}
|
||||
|
||||
private CancellationTokenSource trackedUpdateCancellationSource;
|
||||
private readonly List<CancellationTokenSource> linkedCancellationSources = new List<CancellationTokenSource>();
|
||||
|
||||
/// <summary>
|
||||
/// Updates all tracked <see cref="BindableStarDifficulty"/> using the current ruleset and mods.
|
||||
/// </summary>
|
||||
private void updateTrackedBindables()
|
||||
{
|
||||
trackedUpdateCancellationSource?.Cancel();
|
||||
cancelTrackedBindableUpdate();
|
||||
trackedUpdateCancellationSource = new CancellationTokenSource();
|
||||
|
||||
foreach (var b in trackedBindables)
|
||||
{
|
||||
if (trackedUpdateCancellationSource.IsCancellationRequested)
|
||||
break;
|
||||
var linkedSource = CancellationTokenSource.CreateLinkedTokenSource(trackedUpdateCancellationSource.Token, b.CancellationToken);
|
||||
linkedCancellationSources.Add(linkedSource);
|
||||
|
||||
using (var linkedSource = CancellationTokenSource.CreateLinkedTokenSource(trackedUpdateCancellationSource.Token, b.CancellationToken))
|
||||
updateBindable(b, currentRuleset.Value, currentMods.Value, linkedSource.Token);
|
||||
updateBindable(b, currentRuleset.Value, currentMods.Value, linkedSource.Token);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cancels the existing update of all tracked <see cref="BindableStarDifficulty"/> via <see cref="updateTrackedBindables"/>.
|
||||
/// </summary>
|
||||
private void cancelTrackedBindableUpdate()
|
||||
{
|
||||
trackedUpdateCancellationSource?.Cancel();
|
||||
trackedUpdateCancellationSource = null;
|
||||
|
||||
foreach (var c in linkedCancellationSources)
|
||||
{
|
||||
c.Cancel();
|
||||
c.Dispose();
|
||||
}
|
||||
|
||||
linkedCancellationSources.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the value of a <see cref="BindableStarDifficulty"/> with a given ruleset + mods.
|
||||
/// </summary>
|
||||
@ -220,6 +237,12 @@ namespace osu.Game.Beatmaps
|
||||
return difficultyCache.TryGetValue(key, out existingDifficulty);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
cancelTrackedBindableUpdate();
|
||||
}
|
||||
|
||||
private readonly struct DifficultyCacheLookup : IEquatable<DifficultyCacheLookup>
|
||||
{
|
||||
public readonly int BeatmapId;
|
||||
|
Loading…
Reference in New Issue
Block a user