From 7c281926a51586e4d1d32b1f46c7123e507cb3b0 Mon Sep 17 00:00:00 2001 From: azyges Date: Fri, 16 Jan 2026 19:29:24 +0900 Subject: [PATCH] :sludge: --- LightlessSync/Utils/TaskRegistry.cs | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/LightlessSync/Utils/TaskRegistry.cs b/LightlessSync/Utils/TaskRegistry.cs index 90b6fcf..7104548 100644 --- a/LightlessSync/Utils/TaskRegistry.cs +++ b/LightlessSync/Utils/TaskRegistry.cs @@ -31,34 +31,26 @@ public sealed class TaskRegistry where HandleType : notnull private Task GetOrStartInternal(HandleType handle, Func taskFactory) { - while (true) + Lazy entry = _activeTasks.GetOrAdd(handle, _ => CreateEntry(handle, taskFactory)); + Task task = entry.Value; + if (task.IsCompleted) { - Lazy entry = _activeTasks.GetOrAdd(handle, _ => CreateEntry(handle, taskFactory)); - Task task = entry.Value; - - if (!task.IsCompleted) - { - return task; - } - _activeTasks.TryRemove(new KeyValuePair>(handle, entry)); } + + return task; } private Task GetOrStartInternal(HandleType handle, Func> taskFactory) { - while (true) + Lazy entry = _activeTasks.GetOrAdd(handle, _ => CreateEntry(handle, taskFactory)); + Task task = entry.Value; + if (task.IsCompleted) { - Lazy entry = _activeTasks.GetOrAdd(handle, _ => CreateEntry(handle, taskFactory)); - Task task = entry.Value; - - if (!task.IsCompleted) - { - return (Task)task; - } - _activeTasks.TryRemove(new KeyValuePair>(handle, entry)); } + + return (Task)task; } private Lazy CreateEntry(HandleType handle, Func taskFactory)