1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-21 04:13:21 +08:00

Use CancellationTokenSource to avoid unwanted panels creation

This commit is contained in:
Andrei Zavatski 2019-08-28 01:14:35 +03:00
parent 9b1e8cf48b
commit 2d7024ffd9

View File

@ -17,6 +17,7 @@ using osu.Game.Overlays.Social;
using osu.Game.Users; using osu.Game.Users;
using osu.Framework.Threading; using osu.Framework.Threading;
using System; using System;
using System.Threading;
namespace osu.Game.Overlays namespace osu.Game.Overlays
{ {
@ -92,6 +93,8 @@ namespace osu.Game.Overlays
private void queueUpdate() => Scheduler.AddOnce(updateSearch); private void queueUpdate() => Scheduler.AddOnce(updateSearch);
private CancellationTokenSource loadCancellation;
private void updateSearch() private void updateSearch()
{ {
Scheduler.CancelDelayedTasks(); Scheduler.CancelDelayedTasks();
@ -132,6 +135,8 @@ namespace osu.Game.Overlays
return; return;
} }
loadCancellation = new CancellationTokenSource();
var newPanels = new FillFlowContainer<SocialPanel> var newPanels = new FillFlowContainer<SocialPanel>
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
@ -167,7 +172,7 @@ namespace osu.Game.Overlays
{ {
loading.Hide(); loading.Hide();
ScrollFlow.Add(panels = newPanels); ScrollFlow.Add(panels = newPanels);
}); }, loadCancellation.Token);
} }
private void updateUsers(IEnumerable<User> newUsers) private void updateUsers(IEnumerable<User> newUsers)
@ -212,6 +217,8 @@ namespace osu.Game.Overlays
{ {
loading.Show(); loading.Show();
loadCancellation?.Cancel();
if (panels != null) if (panels != null)
{ {
panels.Expire(); panels.Expire();