Merge pull request #17086 from peppy/fix-profile-badge-cancellation

This commit is contained in:
Salman Ahmed
2022-03-04 10:38:11 +03:00
committed by GitHub

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System.Threading;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
@ -63,11 +64,17 @@ namespace osu.Game.Overlays.Profile.Header
}; };
} }
private CancellationTokenSource cancellationTokenSource;
private void updateDisplay(APIUser user) private void updateDisplay(APIUser user)
{ {
var badges = user.Badges; cancellationTokenSource?.Cancel();
cancellationTokenSource = new CancellationTokenSource();
badgeFlowContainer.Clear(); badgeFlowContainer.Clear();
var badges = user.Badges;
if (badges?.Length > 0) if (badges?.Length > 0)
{ {
Show(); Show();
@ -79,7 +86,7 @@ namespace osu.Game.Overlays.Profile.Header
{ {
// load in stable order regardless of async load order. // load in stable order regardless of async load order.
badgeFlowContainer.Insert(displayIndex, asyncBadge); badgeFlowContainer.Insert(displayIndex, asyncBadge);
}); }, cancellationTokenSource.Token);
} }
} }
else else
@ -87,5 +94,11 @@ namespace osu.Game.Overlays.Profile.Header
Hide(); Hide();
} }
} }
protected override void Dispose(bool isDisposing)
{
cancellationTokenSource?.Cancel();
base.Dispose(isDisposing);
}
} }
} }