Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
martintmk committed Aug 17, 2023
1 parent d09f162 commit f5dc307
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
29 changes: 13 additions & 16 deletions src/Polly.Core/Registry/ResiliencePipelineRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,14 @@ public void Dispose()
{
_disposed = true;

foreach (var pipeline in _pipelines.Values)
{
pipeline.DisposeHelper.ForceDispose();
}

var pipelines = _pipelines.Values.ToList();
_pipelines.Clear();

foreach (var disposable in _genericRegistry.Values.Cast<IDisposable>())
{
disposable.Dispose();
}

var registries = _genericRegistry.Values.Cast<IDisposable>().ToList();
_genericRegistry.Clear();

pipelines.ForEach(p => p.DisposeHelper.ForceDispose());
registries.ForEach(p => p.Dispose());
}

/// <summary>
Expand All @@ -249,19 +244,21 @@ public async ValueTask DisposeAsync()
{
_disposed = true;

foreach (var pipeline in _pipelines.Values)
var pipelines = _pipelines.Values.ToList();
_pipelines.Clear();

var registries = _genericRegistry.Values.Cast<IAsyncDisposable>().ToList();
_genericRegistry.Clear();

foreach (var pipeline in pipelines)
{
await pipeline.DisposeHelper.ForceDisposeAsync().ConfigureAwait(false);
}

_pipelines.Clear();

foreach (var disposable in _genericRegistry.Values.Cast<IAsyncDisposable>())
foreach (var disposable in registries)
{
await disposable.DisposeAsync().ConfigureAwait(false);
}

_genericRegistry.Clear();
}

private static PipelineComponent CreatePipelineComponent<TBuilder>(
Expand Down
7 changes: 1 addition & 6 deletions src/Polly.Core/Utils/ComponentDisposeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ private bool EnsureDisposable()
throw new InvalidOperationException("Disposing this resilience pipeline is not allowed because it is owned by the pipeline registry.");
}

if (_disposed)
{
return false;
}

return true;
return !_disposed;
}
}

0 comments on commit f5dc307

Please sign in to comment.