Table of Contents

Class ReactiveTimer

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

Represents a disposable timer that can be listened to.

public sealed class ReactiveTimer : EventSource<WithInterval<long>>, IEventSource<WithInterval<long>>, IEventStream<WithInterval<long>>, IEventSource, IEventStream, IDisposable, IAsyncDisposable
Inheritance
ReactiveTimer
Implements
Inherited Members
Extension Methods

Constructors

ReactiveTimer(Duration, Duration, ITimestampProvider?, ValueTaskDelaySource?, long)

Creates a new ReactiveTimer instance.

public ReactiveTimer(Duration interval, Duration spinWaitDurationHint, ITimestampProvider? timestampProvider = null, ValueTaskDelaySource? delaySource = null, long count = 9223372036854775807)

Parameters

interval Duration

Interval between subsequent timer events.

spinWaitDurationHint Duration

SpinWait duration hint for this timer.

timestampProvider ITimestampProvider

Optional timestamp provider used for time tracking.

delaySource ValueTaskDelaySource

Optional value task delay source to use for scheduling delays.

count long

Number of events this timer will emit in total. Equal to MaxValue by default.

Exceptions

ArgumentOutOfRangeException

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

ReactiveTimer(Duration, ITimestampProvider?, ValueTaskDelaySource?, long)

Creates a new ReactiveTimer instance.

public ReactiveTimer(Duration interval, ITimestampProvider? timestampProvider = null, ValueTaskDelaySource? delaySource = null, long count = 9223372036854775807)

Parameters

interval Duration

Interval between subsequent timer events.

timestampProvider ITimestampProvider

Optional timestamp provider used for time tracking.

delaySource ValueTaskDelaySource

Optional value task delay source to use for scheduling delays.

count long

Number of events this timer will emit in total. Equal to MaxValue by default.

Exceptions

ArgumentOutOfRangeException

When count is less than 1 or when interval is less than 1 tick or greater than MaxValue milliseconds.

Properties

Count

Number of events this timer will emit in total.

public long Count { get; }

Property Value

long

DefaultSpinWaitDurationHint

Specifies the default SpinWait duration hint. Equal to 1 microsecond.

public static Duration DefaultSpinWaitDurationHint { get; }

Property Value

Duration

Interval

Interval between subsequent timer events.

public Duration Interval { get; }

Property Value

Duration

State

Specifies the current state of this timer.

public ReactiveTimerState State { get; }

Property Value

ReactiveTimerState

Methods

Dispose()

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

public override 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.

Start()

Attempts to start this timer.

public bool Start()

Returns

bool

false when timer was not started because it was not in Idle state, otherwise true.

Exceptions

ObjectDisposedException

The timer has been disposed.

Start(Duration)

Attempts to start this timer with an initial delay.

public bool Start(Duration delay)

Parameters

delay Duration

Time that must elapse before emitting the first event.

Returns

bool

false when timer was not started because it was not in Idle state, otherwise true.

Exceptions

ObjectDisposedException

The timer has been disposed.

ArgumentOutOfRangeException

When delay is less than 1 tick or greater than MaxValue milliseconds.

Stop()

Attempts to stop this timer.

public bool Stop()

Returns

bool

true when timer was marked for stopping, otherwise false.