:sludge:
This commit is contained in:
@@ -31,34 +31,26 @@ public sealed class TaskRegistry<HandleType> where HandleType : notnull
|
|||||||
|
|
||||||
private Task GetOrStartInternal(HandleType handle, Func<Task> taskFactory)
|
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));
|
_activeTasks.TryRemove(new KeyValuePair<HandleType, Lazy<Task>>(handle, entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return task;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task<T> GetOrStartInternal<T>(HandleType handle, Func<Task<T>> taskFactory)
|
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));
|
_activeTasks.TryRemove(new KeyValuePair<HandleType, Lazy<Task>>(handle, entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (Task<T>)task;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Lazy<Task> CreateEntry(HandleType handle, Func<Task> taskFactory)
|
private Lazy<Task> CreateEntry(HandleType handle, Func<Task> taskFactory)
|
||||||
|
|||||||
Reference in New Issue
Block a user