Class ReactiveTimer
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
intervalDurationInterval between subsequent timer events.
spinWaitDurationHintDurationSpinWait duration hint for this timer.
timestampProviderITimestampProviderOptional timestamp provider used for time tracking.
delaySourceValueTaskDelaySourceOptional value task delay source to use for scheduling delays.
countlongNumber of events this timer will emit in total. Equal to MaxValue by default.
Exceptions
- ArgumentOutOfRangeException
When
countis less than 1 or whenintervalis less than 1 tick or greater than MaxValue milliseconds or whenspinWaitDurationHintis 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
intervalDurationInterval between subsequent timer events.
timestampProviderITimestampProviderOptional timestamp provider used for time tracking.
delaySourceValueTaskDelaySourceOptional value task delay source to use for scheduling delays.
countlongNumber of events this timer will emit in total. Equal to MaxValue by default.
Exceptions
- ArgumentOutOfRangeException
When
countis less than 1 or whenintervalis 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
DefaultSpinWaitDurationHint
Specifies the default SpinWait duration hint. Equal to 1 microsecond.
public static Duration DefaultSpinWaitDurationHint { get; }
Property Value
Interval
Interval between subsequent timer events.
public Duration Interval { get; }
Property Value
State
Specifies the current state of this timer.
public ReactiveTimerState State { get; }
Property Value
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
Exceptions
- ObjectDisposedException
The timer has been disposed.
Start(Duration)
Attempts to start this timer with an initial delay.
public bool Start(Duration delay)
Parameters
delayDurationTime that must elapse before emitting the first event.
Returns
Exceptions
- ObjectDisposedException
The timer has been disposed.
- ArgumentOutOfRangeException
When
delayis 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.