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