1
0
mirror of https://github.com/ppy/osu.git synced 2026-05-31 18:31:01 +08:00

Assert that FetchWithCriteria is called from the update thread

This commit is contained in:
Salman Alshamrani
2025-06-22 06:51:39 +03:00
committed by Dean Herbert
Unverified
parent db22bbc870
commit c09f40a8cf
2 changed files with 10 additions and 1 deletions
@@ -7,6 +7,7 @@ using System.Diagnostics;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Development;
using osu.Framework.Graphics;
using osu.Framework.Logging;
using osu.Game.Beatmaps;
@@ -24,7 +25,11 @@ namespace osu.Game.Online.Leaderboards
{
public partial class LeaderboardManager : Component
{
/// <summary>
/// The latest leaderboard scores fetched by the criteria in <see cref="CurrentCriteria"/>.
/// </summary>
public IBindable<LeaderboardScores?> Scores => scores;
private readonly Bindable<LeaderboardScores?> scores = new Bindable<LeaderboardScores?>();
public LeaderboardCriteria? CurrentCriteria { get; private set; }
@@ -47,6 +52,9 @@ namespace osu.Game.Online.Leaderboards
/// </summary>
public void FetchWithCriteria(LeaderboardCriteria newCriteria, bool forceRefresh = false)
{
if (!ThreadSafety.IsUpdateThread)
throw new InvalidOperationException(@$"{nameof(FetchWithCriteria)} must be called from the update thread.");
if (!forceRefresh && CurrentCriteria?.Equals(newCriteria) == true && scores.Value?.FailState == null)
return;
@@ -54,7 +54,8 @@ namespace osu.Game.Screens.Ranking
if (globalScores.Value != null && leaderboardManager.CurrentCriteria?.Equals(criteria) == true)
requestTaskSource.TrySetResult(globalScores.Value);
});
leaderboardManager.FetchWithCriteria(criteria, forceRefresh: true);
Schedule(() => leaderboardManager.FetchWithCriteria(criteria, forceRefresh: true));
var result = await requestTaskSource.Task.ConfigureAwait(false);