mirror of
https://github.com/ppy/osu.git
synced 2025-02-12 23:12:59 +08:00
Merge pull request #31798 from peppy/carousel-v2-async-fix
Fix `Carousel.FilterAsync` not working when called from a non-update thread
This commit is contained in:
commit
ceb424faa1
@ -130,7 +130,7 @@ namespace osu.Game.Tests.Visual.SongSelect
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void SortBy(FilterCriteria criteria) => AddStep($"sort {criteria.Sort} group {criteria.Group}", () => Carousel.Filter(criteria));
|
protected void SortBy(FilterCriteria criteria) => AddStep($"sort:{criteria.Sort} group:{criteria.Group}", () => Carousel.Filter(criteria));
|
||||||
|
|
||||||
protected void WaitForDrawablePanels() => AddUntilStep("drawable panels loaded", () => Carousel.ChildrenOfType<ICarouselPanel>().Count(), () => Is.GreaterThan(0));
|
protected void WaitForDrawablePanels() => AddUntilStep("drawable panels loaded", () => Carousel.ChildrenOfType<ICarouselPanel>().Count(), () => Is.GreaterThan(0));
|
||||||
protected void WaitForSorting() => AddUntilStep("sorting finished", () => Carousel.IsFiltering, () => Is.False);
|
protected void WaitForSorting() => AddUntilStep("sorting finished", () => Carousel.IsFiltering, () => Is.False);
|
||||||
|
@ -228,21 +228,16 @@ namespace osu.Game.Screens.SelectV2
|
|||||||
|
|
||||||
private async Task performFilter()
|
private async Task performFilter()
|
||||||
{
|
{
|
||||||
Debug.Assert(SynchronizationContext.Current != null);
|
|
||||||
|
|
||||||
Stopwatch stopwatch = Stopwatch.StartNew();
|
Stopwatch stopwatch = Stopwatch.StartNew();
|
||||||
var cts = new CancellationTokenSource();
|
var cts = new CancellationTokenSource();
|
||||||
|
|
||||||
lock (this)
|
var previousCancellationSource = Interlocked.Exchange(ref cancellationSource, cts);
|
||||||
{
|
await previousCancellationSource.CancelAsync().ConfigureAwait(false);
|
||||||
cancellationSource.Cancel();
|
|
||||||
cancellationSource = cts;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (DebounceDelay > 0)
|
if (DebounceDelay > 0)
|
||||||
{
|
{
|
||||||
log($"Filter operation queued, waiting for {DebounceDelay} ms debounce");
|
log($"Filter operation queued, waiting for {DebounceDelay} ms debounce");
|
||||||
await Task.Delay(DebounceDelay, cts.Token).ConfigureAwait(true);
|
await Task.Delay(DebounceDelay, cts.Token).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy must be performed on update thread for now (see ConfigureAwait above).
|
// Copy must be performed on update thread for now (see ConfigureAwait above).
|
||||||
@ -266,19 +261,22 @@ namespace osu.Game.Screens.SelectV2
|
|||||||
{
|
{
|
||||||
log("Cancelled due to newer request arriving");
|
log("Cancelled due to newer request arriving");
|
||||||
}
|
}
|
||||||
}, cts.Token).ConfigureAwait(true);
|
}, cts.Token).ConfigureAwait(false);
|
||||||
|
|
||||||
if (cts.Token.IsCancellationRequested)
|
if (cts.Token.IsCancellationRequested)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
log("Items ready for display");
|
Schedule(() =>
|
||||||
carouselItems = items.ToList();
|
{
|
||||||
displayedRange = null;
|
log("Items ready for display");
|
||||||
|
carouselItems = items.ToList();
|
||||||
|
displayedRange = null;
|
||||||
|
|
||||||
// Need to call this to ensure correct post-selection logic is handled on the new items list.
|
// Need to call this to ensure correct post-selection logic is handled on the new items list.
|
||||||
HandleItemSelected(currentSelection.Model);
|
HandleItemSelected(currentSelection.Model);
|
||||||
|
|
||||||
refreshAfterSelection();
|
refreshAfterSelection();
|
||||||
|
});
|
||||||
|
|
||||||
void log(string text) => Logger.Log($"Carousel[op {cts.GetHashCode().ToString()}] {stopwatch.ElapsedMilliseconds} ms: {text}");
|
void log(string text) => Logger.Log($"Carousel[op {cts.GetHashCode().ToString()}] {stopwatch.ElapsedMilliseconds} ms: {text}");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user