1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 15:03:13 +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 osu.Game.Users;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading;
namespace osu.Game.Overlays.Profile.Sections namespace osu.Game.Overlays.Profile.Sections
{ {
@ -21,6 +22,7 @@ namespace osu.Game.Overlays.Profile.Sections
private readonly ShowMoreButton moreButton; private readonly ShowMoreButton moreButton;
private readonly OsuSpriteText missingText; private readonly OsuSpriteText missingText;
private APIRequest<List<T>> retrievalRequest; private APIRequest<List<T>> retrievalRequest;
private CancellationTokenSource loadCancellation;
[Resolved] [Resolved]
private IAPIProvider api { get; set; } private IAPIProvider api { get; set; }
@ -82,6 +84,7 @@ namespace osu.Game.Overlays.Profile.Sections
private void onUserChanged(ValueChangedEvent<User> e) private void onUserChanged(ValueChangedEvent<User> e)
{ {
loadCancellation?.Cancel();
retrievalRequest?.Cancel(); retrievalRequest?.Cancel();
VisiblePages = 0; VisiblePages = 0;
@ -93,6 +96,8 @@ namespace osu.Game.Overlays.Profile.Sections
private void showMore() private void showMore()
{ {
loadCancellation = new CancellationTokenSource();
retrievalRequest = CreateRequest(); retrievalRequest = CreateRequest();
retrievalRequest.Success += UpdateItems; retrievalRequest.Success += UpdateItems;
@ -118,7 +123,7 @@ namespace osu.Game.Overlays.Profile.Sections
moreButton.IsLoading = false; moreButton.IsLoading = false;
ItemsContainer.AddRange(drawables); ItemsContainer.AddRange(drawables);
}); }, loadCancellation.Token);
}); });
} }