From 4f7b3e2112031eac52deb43ca502b6bc065cfd84 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 11 Jun 2024 13:24:25 +0800 Subject: [PATCH] Limit concurrency using a semaphore instead of dodgy task factory --- GlobalRankLookupCache/Controllers/BeatmapRankCache.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/GlobalRankLookupCache/Controllers/BeatmapRankCache.cs b/GlobalRankLookupCache/Controllers/BeatmapRankCache.cs index 946235c..15675a3 100644 --- a/GlobalRankLookupCache/Controllers/BeatmapRankCache.cs +++ b/GlobalRankLookupCache/Controllers/BeatmapRankCache.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; -using osu.Framework.Threading; namespace GlobalRankLookupCache.Controllers { @@ -84,17 +84,17 @@ private void queuePopulation() if (!populationInProgress) { populationInProgress = true; - task_factory.StartNew(repopulateScores); + Task.Run(repopulateScores); } } } - private static readonly ThreadedTaskScheduler task_scheduler = new ThreadedTaskScheduler(10, "retrieval"); - - private static readonly TaskFactory task_factory = new TaskFactory(task_scheduler); + private static readonly SemaphoreSlim population_tasks_semaphore = new SemaphoreSlim(10); private async Task repopulateScores() { + await population_tasks_semaphore.WaitAsync(); + var scores = new List(); try @@ -138,6 +138,7 @@ private async Task repopulateScores() // will retry next lookup } + population_tasks_semaphore.Release(); populationInProgress = false; } }