Table of Contents

Class ReactiveScheduler<TKey>

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

Represents a scheduler of IScheduleTask<TKey> instances.

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

Type Parameters

TKey

Task key type.

Inheritance
ReactiveScheduler<TKey>
Implements
Inherited Members

Constructors

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

Creates a new empty ReactiveScheduler<TKey> instance.

public ReactiveScheduler(ITimestampProvider timestamps, IEqualityComparer<TKey>? keyComparer = null, Duration? defaultInterval = null, Duration? spinWaitDurationHint = null)

Parameters

timestamps ITimestampProvider

ITimestampProvider instance used for time tracking.

keyComparer IEqualityComparer<TKey>

Key equality comparer. Equal to Default by default.

defaultInterval Duration?

Maximum Duration to hang the underlying time tracking mechanism for. Equal to 1 hour by default.

spinWaitDurationHint Duration?

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

Exceptions

ArgumentOutOfRangeException

When defaultInterval is less than 1 tick or greater than MaxValue milliseconds or when spinWaitDurationHint is less than 0.

Properties

DefaultInterval

Maximum Duration to hang the underlying time tracking mechanism for.

public Duration DefaultInterval { get; }

Property Value

Duration

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

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()

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()

Starts this scheduler synchronously. Does nothing when this scheduler has already been started.

public void Start()

StartAsync(TaskScheduler?)

Starts this scheduler asynchronously.

public Task StartAsync(TaskScheduler? scheduler = null)

Parameters

scheduler TaskScheduler

Optional task scheduler.

Returns

Task

New Task instance that completes when this scheduler is done or CompletedTask when this scheduler has already been started.

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.