Table of Contents

Class ReactiveScheduler<TKey>

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

Represents a scheduler of IScheduleTask<TKey> instances.

public sealed class ReactiveScheduler<TKey> : IReactiveScheduler<TKey>, IDisposable, IAsyncDisposable where TKey : notnull

Type Parameters

TKey

Task key type.

Inheritance
ReactiveScheduler<TKey>
Implements
Inherited Members

Constructors

ReactiveScheduler(ITimestampProvider?, ValueTaskDelaySource?, IEqualityComparer<TKey>?, Duration?, Duration)

Creates a new empty ReactiveScheduler<TKey> instance.

public ReactiveScheduler(ITimestampProvider? timestamps = null, ValueTaskDelaySource? delaySource = null, IEqualityComparer<TKey>? keyComparer = null, Duration? spinWaitDurationHint = null, Duration taskDisposalTimeout = default)

Parameters

timestamps ITimestampProvider

Optional ITimestampProvider instance used for time tracking.

delaySource ValueTaskDelaySource

Optional value task delay source to use for scheduling delays.

keyComparer IEqualityComparer<TKey>

Key equality comparer. Equal to Default by default.

spinWaitDurationHint Duration?

SpinWait duration hint for the underlying time tracking mechanism. Equal to 1 microsecond by default.

taskDisposalTimeout Duration

Max time the disposal of scheduled tasks will wait for their invocations to complete. Equal to Zero by default.

Exceptions

ArgumentOutOfRangeException

When spinWaitDurationHint is less than 0.

Properties

KeyComparer

Key equality comparer.

public IEqualityComparer<TKey> KeyComparer { get; }

Property Value

IEqualityComparer<TKey>

SpinWaitDurationHint

SpinWait duration hint for the underlying time tracking mechanism.

public Duration SpinWaitDurationHint { get; }

Property Value

Duration

StartTimestamp

Timestamp of creation of this scheduler.

public Timestamp StartTimestamp { get; }

Property Value

Timestamp

State

Specifies the current state of this scheduler.

public ReactiveSchedulerState State { get; }

Property Value

ReactiveSchedulerState

TaskDisposalTimeout

Max time the disposal of scheduled tasks will wait for their invocations to complete.

public Duration TaskDisposalTimeout { get; }

Property Value

Duration

TaskKeys

Collection of registered task keys.

public IReadOnlyCollection<TKey> TaskKeys { get; }

Property Value

IReadOnlyCollection<TKey>

Timestamps

ITimestampProvider instance used for time tracking.

public ITimestampProvider Timestamps { get; }

Property Value

ITimestampProvider

Methods

Clear()

Removes and disposes all currently registered tasks.

public void Clear()

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

public ValueTask DisposeAsync()

Returns

ValueTask

A task that represents the asynchronous dispose operation.

MakeInfinite(TKey)

Attempts to make the task associated with the specified key repeat infinitely.

public bool MakeInfinite(TKey key)

Parameters

key TKey

Task key.

Returns

bool

true when task was updated, otherwise false.

Remove(TKey)

Attempts to remove and dispose a task with the specified key.

public bool Remove(TKey key)

Parameters

key TKey

Key to remove.

Returns

bool

true when task was removed, otherwise false.

Schedule(IScheduleTask<TKey>, Timestamp)

Attempts to schedule the provided task.

public bool Schedule(IScheduleTask<TKey> task, Timestamp timestamp)

Parameters

task IScheduleTask<TKey>

Task to schedule.

timestamp Timestamp

Timestamp that specifies when the scheduled task should be invoked.

Returns

bool

true when task was scheduled, otherwise false.

Remarks

When task key already exists, then the entry will be updated only if the key is associated exactly with the provided task and it is not in the process of being disposed.

Schedule(IScheduleTask<TKey>, Timestamp, Duration, int)

Attempts to schedule the provided task that repeats the specified number of times.

public bool Schedule(IScheduleTask<TKey> task, Timestamp firstTimestamp, Duration interval, int repetitions)

Parameters

task IScheduleTask<TKey>

Task to schedule.

firstTimestamp Timestamp

Timestamp that specifies when the scheduled task should be invoked for the first time.

interval Duration

Interval between subsequent task invocations.

repetitions int

Number of repetitions.

Returns

bool

true when task was scheduled, otherwise false.

Remarks

When task key already exists, then the entry will be updated only if the key is associated exactly with the provided task and it is not in the process of being disposed.

Exceptions

ArgumentOutOfRangeException

When interval is less than 1 tick.

ScheduleInfinite(IScheduleTask<TKey>, Timestamp, Duration)

Attempts to schedule the provided task that repeats infinitely.

public bool ScheduleInfinite(IScheduleTask<TKey> task, Timestamp firstTimestamp, Duration interval)

Parameters

task IScheduleTask<TKey>

Task to schedule.

firstTimestamp Timestamp

Timestamp that specifies when the scheduled task should be invoked for the first time.

interval Duration

Interval between subsequent task invocations.

Returns

bool

true when task was scheduled, otherwise false.

Remarks

When task key already exists, then the entry will be updated only if the key is associated exactly with the provided task and it is not in the process of being disposed.

Exceptions

ArgumentOutOfRangeException

When interval is less than 1 tick.

SetInterval(TKey, Duration)

Attempts to change the interval of the task associated with the specified key.

public bool SetInterval(TKey key, Duration interval)

Parameters

key TKey

Task key.

interval Duration

Interval between subsequent task invocations.

Returns

bool

true when task was updated, otherwise false.

Exceptions

ArgumentOutOfRangeException

When interval is less than 1 tick.

SetNextTimestamp(TKey, Timestamp)

Attempts to change the next timestamp of the task associated with the specified key.

public bool SetNextTimestamp(TKey key, Timestamp timestamp)

Parameters

key TKey

Task key.

timestamp Timestamp

Timestamp that specifies when the scheduled task should be invoked next.

Returns

bool

true when task was updated, otherwise false.

SetRepetitions(TKey, int)

Attempts to change the number of repetitions of the task associated with the specified key.

public bool SetRepetitions(TKey key, int repetitions)

Parameters

key TKey

Task key.

repetitions int

Number of repetitions.

Returns

bool

true when task was updated, otherwise false.

Exceptions

ArgumentOutOfRangeException

When repetitions is less than 1.

Start()

Attempts to start this scheduler.

public bool Start()

Returns

bool

false when scheduler was not started because it was not in Created state, otherwise true.

TryGetTaskState(TKey)

Attempts to create a ScheduleTaskState<TKey> instance for the given task key.

[Pure]
public ScheduleTaskState<TKey>? TryGetTaskState(TKey key)

Parameters

key TKey

Task key to create a snapshot for.

Returns

ScheduleTaskState<TKey>

New ScheduleTaskState<TKey> instance or null when task does not exist.