Use cansellation token

This commit is contained in:
Andrei Zavatski 2019-08-23 14:52:26 +03:00
parent 7e34afeab8
commit 0cde0982e5
1 changed files with 6 additions and 1 deletions

View File

@ -13,6 +13,7 @@
using osu.Game.Users;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
namespace osu.Game.Overlays.Profile.Sections
{
@ -21,6 +22,7 @@ public abstract class PaginatedContainer<T> : FillFlowContainer
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 @@ private void load(RulesetStore rulesets)
private void onUserChanged(ValueChangedEvent<User> e)
{
loadCancellation?.Cancel();
retrievalRequest?.Cancel();
VisiblePages = 0;
@ -93,6 +96,8 @@ private void onUserChanged(ValueChangedEvent<User> e)
private void showMore()
{
loadCancellation = new CancellationTokenSource();
retrievalRequest = CreateRequest();
retrievalRequest.Success += UpdateItems;
@ -118,7 +123,7 @@ protected virtual void UpdateItems(List<T> items)
moreButton.IsLoading = false;
ItemsContainer.AddRange(drawables);
});
}, loadCancellation.Token);
});
}