This commit is contained in:
2026-01-16 19:29:24 +09:00
parent 6c7e4e6303
commit 7c281926a5

View File

@@ -31,34 +31,26 @@ public sealed class TaskRegistry<HandleType> where HandleType : notnull
private Task GetOrStartInternal(HandleType handle, Func<Task> taskFactory)
{
while (true)
Lazy<Task> entry = _activeTasks.GetOrAdd(handle, _ => CreateEntry(handle, taskFactory));
Task task = entry.Value;
if (task.IsCompleted)
{
Lazy<Task> entry = _activeTasks.GetOrAdd(handle, _ => CreateEntry(handle, taskFactory));
Task task = entry.Value;
if (!task.IsCompleted)
{
return task;
}
_activeTasks.TryRemove(new KeyValuePair<HandleType, Lazy<Task>>(handle, entry));
}
return task;
}
private Task<T> GetOrStartInternal<T>(HandleType handle, Func<Task<T>> taskFactory)
{
while (true)
Lazy<Task> entry = _activeTasks.GetOrAdd(handle, _ => CreateEntry(handle, taskFactory));
Task task = entry.Value;
if (task.IsCompleted)
{
Lazy<Task> entry = _activeTasks.GetOrAdd(handle, _ => CreateEntry(handle, taskFactory));
Task task = entry.Value;
if (!task.IsCompleted)
{
return (Task<T>)task;
}
_activeTasks.TryRemove(new KeyValuePair<HandleType, Lazy<Task>>(handle, entry));
}
return (Task<T>)task;
}
private Lazy<Task> CreateEntry(HandleType handle, Func<Task> taskFactory)