- 
                Notifications
    You must be signed in to change notification settings 
- Fork 10.5k
Open
Labels
api-ready-for-reviewAPI is ready for formal API review - https://github.com/dotnet/apireviewsAPI is ready for formal API review - https://github.com/dotnet/apireviewsarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Milestone
Description
Background and Motivation
It would be nice to be able to emit a metric anytime the DefaultObjectPool limit is breached. Currently this is not possible because the bool ReturnCore is marked private protected so it cannot be overridden to get the bool response from this method. If the _numbItems was encapsulated as a Property {get}, than it would be possible to determine if the pool is full.
Proposed API
public class DefaultObjectPool<T> : ObjectPool<T> where T : class
{
    private readonly Func<T> _createFunc;
    private readonly Func<T, bool> _returnFunc;
    private readonly int _maxCapacity;
    private int _numItems;
    private protected readonly ConcurrentQueue<T> _items = new();
    private protected T? _fastItem;
    
+   public int ItemCount => _numItems;Usage Examples
// return item to the pool:
pool.Return(item);
// is it full?
if (pool.ItemCount == _maximumRetained)
{
   // emit metric for tracking
}Alternative Designs
- Remove privatefrom theprivate protected bool ReturnCoreso it can be overridden, call the base class to get the boolean response and emit the metric there.
- Change ObjectPool<T>.void Return(T obj)toObjectPool<T>.bool Return(T obj)
Risks
The least risk is to expose the int property so that the underlying APIs to need to change. I don't foresee any risks by exposing the ItemCount property.
Metadata
Metadata
Assignees
Labels
api-ready-for-reviewAPI is ready for formal API review - https://github.com/dotnet/apireviewsAPI is ready for formal API review - https://github.com/dotnet/apireviewsarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions