-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce ResilienceContextPool (ApiReview) (#1421)
- Loading branch information
Showing
64 changed files
with
387 additions
and
334 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace Polly; | ||
|
||
public abstract partial class ResilienceContextPool | ||
{ | ||
private sealed class SharedPool : ResilienceContextPool | ||
{ | ||
private readonly ObjectPool<ResilienceContext> _pool = new(static () => new ResilienceContext(), static c => c.Reset()); | ||
|
||
public override ResilienceContext Get(string? operationKey, CancellationToken cancellationToken = default) | ||
{ | ||
var context = _pool.Get(); | ||
|
||
context.OperationKey = operationKey; | ||
context.CancellationToken = cancellationToken; | ||
|
||
return context; | ||
} | ||
|
||
public override void Return(ResilienceContext context) => _pool.Return(Guard.NotNull(context)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
namespace Polly; | ||
|
||
#pragma warning disable CA1716 // Identifiers should not match keywords | ||
#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters | ||
|
||
/// <summary> | ||
/// The pool of <see cref="ResilienceContext"/> instances. | ||
/// </summary> | ||
public abstract partial class ResilienceContextPool | ||
{ | ||
/// <summary> | ||
/// Gets the shared pool instance. | ||
/// </summary> | ||
public static ResilienceContextPool Shared { get; } = new SharedPool(); | ||
|
||
/// <summary> | ||
/// Gets a <see cref="ResilienceContext"/> instance from the pool. | ||
/// </summary> | ||
/// <param name="cancellationToken">The cancellation token.</param> | ||
/// <returns>An instance of <see cref="ResilienceContext"/>.</returns> | ||
/// <remarks> | ||
/// After the execution is finished you should return the <see cref="ResilienceContext"/> back to the pool | ||
/// by calling <see cref="Return(ResilienceContext)"/> method. | ||
/// </remarks> | ||
public ResilienceContext Get(CancellationToken cancellationToken = default) => Get(null, cancellationToken); | ||
|
||
/// <summary> | ||
/// Gets a <see cref="ResilienceContext"/> instance from the pool. | ||
/// </summary> | ||
/// <param name="operationKey">An operation key associated with the context.</param> | ||
/// <param name="cancellationToken">The cancellation token.</param> | ||
/// <returns>An instance of <see cref="ResilienceContext"/>.</returns> | ||
/// <remarks> | ||
/// After the execution is finished you should return the <see cref="ResilienceContext"/> back to the pool | ||
/// by calling <see cref="Return(ResilienceContext)"/> method. | ||
/// </remarks> | ||
public abstract ResilienceContext Get(string? operationKey, CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Returns a <paramref name="context"/> back to the pool. | ||
/// </summary> | ||
/// <param name="context">The context instance.</param> | ||
/// <exception cref="ArgumentNullException">Thrown when <paramref name="context"/> is <see langword="null"/>.</exception> | ||
public abstract void Return(ResilienceContext context); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.