Table of Contents

Class PeriodicBatch<T>

Namespace
LfrlAnvil.Chrono.Async
Assembly
LfrlAnvil.Chrono.dll

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

T

Element type.

Inheritance
PeriodicBatch<T>
Implements
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

delaySource ValueTaskDelaySource

Delay source to use for scheduling auto-flushing.

autoFlushDelay Duration

Specifies the delay with which auto-flush should be scheduled after first item was added to an empty batch.

queueOverflowStrategy BatchQueueOverflowStrategy

Specifies 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.

autoFlushCount int

Specifies 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.

queueSizeLimitHint int

Specifies 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.

minInitialCapacity int

Specifies minimum initial capacity of the internal queue. Equal to 0 by default.

Exceptions

ArgumentOutOfRangeException

When autoFlushDelay is less than or equal to Zero or when autoFlushCount is 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

Duration

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

items QueueSlimMemory<T>

Range of enqueued elements.

autoFlushing bool

Specifies 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.