Class ObjectPool<T>
Describes a simple object pool.
Implements
System.IDisposable
System.IAsyncDisposable
System.Collections.Generic.IReadOnlyCollection<T>
System.Collections.Generic.IEnumerable<T>
System.Collections.IEnumerable
Inherited Members
Namespace: Solti.Utils.Primitives.Threading
Assembly: Solti.Utils.Primitives.dll
Syntax
public class ObjectPool<T> : Disposable, IDisposableEx where T : class
Type Parameters
| Name | Description |
|---|---|
| T |
Constructors
ObjectPool(ILifetimeManager<T>, PoolConfig)
Creates a new ObjectPool<T> object.
Declaration
public ObjectPool(ILifetimeManager<T> lifetimeManager, PoolConfig config = null)
Parameters
| Type | Name | Description |
|---|---|---|
| ILifetimeManager<T> | lifetimeManager | |
| PoolConfig | config |
ObjectPool(Func<T>, PoolConfig)
Creates a new ObjectPool<T> object.
Declaration
public ObjectPool(Func<T> factory, PoolConfig config = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Func<T> | factory | |
| PoolConfig | config |
Properties
Config
The pool configuration.
Declaration
public PoolConfig Config { get; }
Property Value
| Type | Description |
|---|---|
| PoolConfig |
Count
The count of created objects.
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
LifetimeManager
The ILifetimeManager<T> of the items exposed by this pool.
Declaration
public ILifetimeManager<T> LifetimeManager { get; }
Property Value
| Type | Description |
|---|---|
| ILifetimeManager<T> |
Methods
Dispose(Boolean)
Method to be overridden to implement custom disposal logic.
Declaration
protected override void Dispose(bool disposeManaged)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | disposeManaged | It is set to true on System.IDisposable.Dispose call. |
Overrides
Get(CancellationToken)
Gets a value from the pool.
Declaration
public IPoolItem<T> Get(CancellationToken cancellation = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Threading.CancellationToken | cancellation |
Returns
| Type | Description |
|---|---|
| IPoolItem<T> |
GetEnumerator()
Enumerates the already produced items.
Declaration
public IEnumerator<T> GetEnumerator()
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.IEnumerator<T> |
Implements
System.IDisposable
System.IAsyncDisposable
System.Collections.Generic.IReadOnlyCollection<>
System.Collections.Generic.IEnumerable<>
System.Collections.IEnumerable