Class PeriodicBatch<T>
Represents a queue of elements, which are processed in batches, automatically or on demand, with delayed auto-flushing.
public abstract class PeriodicBatch<T> : Batch<T>, IBatch<T>, IDisposable, IAsyncDisposable
Type Parameters
TElement type.
- Inheritance
-
Batch<T>PeriodicBatch<T>
- Implements
-
IBatch<T>
- Inherited Members
Constructors
PeriodicBatch(ValueTaskDelaySource, Duration, BatchQueueOverflowStrategy, int, int, int)
Creates a new PeriodicBatch<T> instance.
protected PeriodicBatch(ValueTaskDelaySource delaySource, Duration autoFlushDelay, BatchQueueOverflowStrategy queueOverflowStrategy = BatchQueueOverflowStrategy.DiscardLast, int autoFlushCount = 1000, int queueSizeLimitHint = 100000000, int minInitialCapacity = 0)
Parameters
delaySourceValueTaskDelaySourceDelay source to use for scheduling auto-flushing.
autoFlushDelayDurationSpecifies the delay with which auto-flush should be scheduled after first item was added to an empty batch.
queueOverflowStrategyBatchQueueOverflowStrategySpecifies the maximum number of enqueued elements that, when exceeded while adding new elements, will cause this batch to react according to its QueueOverflowStrategy. Equal to DiscardLast by default.
autoFlushCountintSpecifies the number of enqueued elements, which acts as a threshold that, when reached while adding new elements, will cause this batch to automatically Flush() itself. Equal to 1 000 by default.
queueSizeLimitHintintSpecifies the maximum number of enqueued elements that, when exceeded while adding new elements, will cause this batch to react according to its QueueOverflowStrategy. Equal to 100 000 000 by default.
minInitialCapacityintSpecifies minimum initial capacity of the internal queue. Equal to 0 by default.
Exceptions
- ArgumentOutOfRangeException
When
autoFlushDelayis less than or equal to Zero or whenautoFlushCountis less than 1.
Properties
AutoFlushDelay
Specifies the delay with which auto-flush should be scheduled after first item was added to an empty batch.
public Duration AutoFlushDelay { get; }
Property Value
Methods
OnDisposed()
Allows to react to the batch being disposed.
protected override void OnDisposed()
Remarks
Exceptions thrown by this method will be completely ignored. The batch will not have any enqueued elements at the moment of invocation of this method.
OnEnqueued(QueueSlimMemory<T>, bool)
Allows to react to a non-empty range of elements being enqueued.
protected override void OnEnqueued(QueueSlimMemory<T> items, bool autoFlushing)
Parameters
itemsQueueSlimMemory<T>Range of enqueued elements.
autoFlushingboolSpecifies whether this batch will be automatically flushed due to the combination of its AutoFlushCount and new elements being added.
Remarks
Exceptions thrown by this method will be completely ignored.