diff --git a/osu.Game.Tests/Visual/SongSelectV2/BeatmapCarouselTestScene.cs b/osu.Game.Tests/Visual/SongSelectV2/BeatmapCarouselTestScene.cs index 649dc7f6a4..8c842b726e 100644 --- a/osu.Game.Tests/Visual/SongSelectV2/BeatmapCarouselTestScene.cs +++ b/osu.Game.Tests/Visual/SongSelectV2/BeatmapCarouselTestScene.cs @@ -4,9 +4,11 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Bindables; +using osu.Framework.Extensions; using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -35,7 +37,7 @@ namespace osu.Game.Tests.Visual.SongSelectV2 { protected readonly BindableList BeatmapSets = new BindableList(); - protected BeatmapCarousel Carousel = null!; + protected TestBeatmapCarousel Carousel = null!; protected OsuScrollContainer Scroll => Carousel.ChildrenOfType>().Single(); @@ -100,7 +102,7 @@ namespace osu.Game.Tests.Visual.SongSelectV2 }, new Drawable[] { - Carousel = new BeatmapCarousel + Carousel = new TestBeatmapCarousel { NewItemsPresented = () => NewItemsPresentedInvocationCount++, BleedTop = 50, @@ -351,5 +353,21 @@ namespace osu.Game.Tests.Visual.SongSelectV2 }); } } + + public class TestBeatmapCarousel : BeatmapCarousel + { + public IEnumerable PostFilterBeatmaps = null!; + + protected override Task> FilterAsync() + { + var filterAsync = base.FilterAsync(); + filterAsync.ContinueWith(result => + { + if (result.IsCompletedSuccessfully) + PostFilterBeatmaps = result.GetResultSafely().Select(i => i.Model).OfType(); + }); + return filterAsync; + } + } } } diff --git a/osu.Game/Graphics/Carousel/Carousel.cs b/osu.Game/Graphics/Carousel/Carousel.cs index 4bcfadf090..ca6f50c9a3 100644 --- a/osu.Game/Graphics/Carousel/Carousel.cs +++ b/osu.Game/Graphics/Carousel/Carousel.cs @@ -170,7 +170,7 @@ namespace osu.Game.Graphics.Carousel /// /// Queue an asynchronous filter operation. /// - protected Task FilterAsync() + protected virtual Task> FilterAsync() { filterTask = performFilter(); filterTask.FireAndForget(); @@ -257,10 +257,10 @@ namespace osu.Game.Graphics.Carousel private List? carouselItems; - private Task filterTask = Task.CompletedTask; + private Task> filterTask = Task.FromResult(Enumerable.Empty()); private CancellationTokenSource cancellationSource = new CancellationTokenSource(); - private async Task performFilter() + private async Task> performFilter() { Stopwatch stopwatch = Stopwatch.StartNew(); var cts = new CancellationTokenSource(); @@ -303,7 +303,7 @@ namespace osu.Game.Graphics.Carousel }, cts.Token).ConfigureAwait(false); if (cts.Token.IsCancellationRequested) - return; + return Enumerable.Empty(); Schedule(() => { @@ -319,6 +319,8 @@ namespace osu.Game.Graphics.Carousel NewItemsPresented?.Invoke(); }); + return items; + void log(string text) => Logger.Log($"Carousel[op {cts.GetHashCode().ToString()}] {stopwatch.ElapsedMilliseconds} ms: {text}"); }