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

Clean up cancellation logic

This commit is contained in:
Dean Herbert 2020-05-14 14:33:31 +09:00
parent fa3373e5f3
commit 04c9973526

View File

@ -122,6 +122,7 @@ namespace osu.Game.Overlays.BeatmapListing
{
if (beatmapListingPager == null || !beatmapListingPager.CanFetchNextPage)
return;
if (queryPagingDebounce != null)
return;
@ -132,14 +133,15 @@ namespace osu.Game.Overlays.BeatmapListing
{
SearchStarted?.Invoke();
beatmapListingPager?.Reset();
cancelSearch();
queryChangedDebounce?.Cancel();
queryChangedDebounce = Scheduler.AddDelayed(updateSearch, queryTextChanged ? 500 : 100);
}
private void updateSearch()
{
cancelSearch();
beatmapListingPager = new BeatmapListingPager(
api,
rulesets,
@ -150,13 +152,20 @@ namespace osu.Game.Overlays.BeatmapListing
sortControl.SortDirection.Value
);
queryPagingDebounce?.Cancel();
queryPagingDebounce = null;
beatmapListingPager.PageFetched += onSearchFinished;
ShowMore();
}
private void cancelSearch()
{
beatmapListingPager?.Reset();
queryChangedDebounce?.Cancel();
queryPagingDebounce?.Cancel();
queryPagingDebounce = null;
}
private void onSearchFinished(List<BeatmapSetInfo> beatmaps)
{
queryPagingDebounce = Scheduler.AddDelayed(() => queryPagingDebounce = null, 1000);
@ -171,9 +180,7 @@ namespace osu.Game.Overlays.BeatmapListing
protected override void Dispose(bool isDisposing)
{
beatmapListingPager?.Reset();
queryChangedDebounce?.Cancel();
queryPagingDebounce?.Cancel();
cancelSearch();
base.Dispose(isDisposing);
}