Table of Contents

Class ReactiveSchedulerBatch<TKey, T>

Namespace
LfrlAnvil.Reactive.Chrono
Assembly
LfrlAnvil.Reactive.Chrono.dll

Represents a queue of elements, which are processed in batches, automatically or on demand, with auto-flushing registered via a ReactiveScheduler<TKey>.

public abstract class ReactiveSchedulerBatch<TKey, T> : Batch<T>, IBatch<T>, IDisposable, IAsyncDisposable where TKey : notnull

Type Parameters

TKey

Scheduler task's key type.

T

Element type.

Inheritance
ReactiveSchedulerBatch<TKey, T>
Implements
Inherited Members

Constructors

ReactiveSchedulerBatch(IReactiveScheduler<TKey>, TKey, Duration, BatchQueueOverflowStrategy, int, int, int)

Creates a new ReactiveSchedulerBatch<TKey, T> instance.

protected ReactiveSchedulerBatch(IReactiveScheduler<TKey> scheduler, TKey key, Duration autoFlushDelay, BatchQueueOverflowStrategy queueOverflowStrategy = BatchQueueOverflowStrategy.DiscardLast, int autoFlushCount = 1000, int queueSizeLimitHint = 100000000, int minInitialCapacity = 0)

Parameters

scheduler IReactiveScheduler<TKey>

Scheduler in which to register auto-flush task.

key TKey

Identifier of the auto-flush task in the scheduler.

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.

InvalidOperationException

When auto-flush task could not be registered in the provided scheduler, either because the scheduler is disposed or a task with the provided key already exists.

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

Scheduler

Scheduler in which auto-flush task is registered.

public IReactiveScheduler<TKey> Scheduler { get; }

Property Value

IReactiveScheduler<TKey>

SchedulerKey

Identifier of the auto-flush task in the Scheduler.

public TKey SchedulerKey { get; }

Property Value

TKey

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.