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

Use cansellation token

This commit is contained in:
Andrei Zavatski 2019-08-23 14:52:26 +03:00
parent 7e34afeab8
commit 0cde0982e5

View File

@ -13,6 +13,7 @@ using osu.Game.Rulesets;
using osu.Game.Users;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
namespace osu.Game.Overlays.Profile.Sections
{
@ -21,6 +22,7 @@ namespace osu.Game.Overlays.Profile.Sections
private readonly ShowMoreButton moreButton;
private readonly OsuSpriteText missingText;
private APIRequest<List<T>> retrievalRequest;
private CancellationTokenSource loadCancellation;
[Resolved]
private IAPIProvider api { get; set; }
@ -82,6 +84,7 @@ namespace osu.Game.Overlays.Profile.Sections
private void onUserChanged(ValueChangedEvent<User> e)
{
loadCancellation?.Cancel();
retrievalRequest?.Cancel();
VisiblePages = 0;
@ -93,6 +96,8 @@ namespace osu.Game.Overlays.Profile.Sections
private void showMore()
{
loadCancellation = new CancellationTokenSource();
retrievalRequest = CreateRequest();
retrievalRequest.Success += UpdateItems;
@ -118,7 +123,7 @@ namespace osu.Game.Overlays.Profile.Sections
moreButton.IsLoading = false;
ItemsContainer.AddRange(drawables);
});
}, loadCancellation.Token);
});
}