Class Delayer
- Namespace
- Garyon.Mechanisms
- Assembly
- Garyon.dll
Represents a delayer that keeps track of the next time moment that it can be unblocked, allowing awaiting the next unblock.
public sealed class Delayer
- Inheritance
-
Delayer
- Inherited Members
- Extension Methods
Properties
IsWaiting
Denotes whether the delayer has registered a task for awaiting the next unblock.
public bool IsWaiting { get; }
Property Value
Methods
CancelUnblock()
Cancels the next unblock time, effectively unblocking the delayer and allowing any unblock time to be set.
public void CancelUnblock()
Remarks
If an active await task is present, it will be ignored but not cancelled. The task returned from WaitUnblock(CancellationToken) must have its cancellation token signal the cancellation manually in order to avoid waiting for the original unblock time.
ExtendNextUnblock(DateTime)
Sets the next unblock to the specified DateTime.
public void ExtendNextUnblock(DateTime next)
Parameters
nextDateTimeThe time to set the next unblock time to.
Remarks
If the next unblock is already set to a later time, this method does not overwrite the next unblock time.
SetFutureUnblock(TimeSpan)
public void SetFutureUnblock(TimeSpan span)
Parameters
spanTimeSpanThe timespan representing the offset from the current time.
Remarks
If the next unblock is already set to a later time, this method does not overwrite the next unblock time.
WaitUnblock(CancellationToken)
Waits until the unblock time is reached. This allows consecutive unblock time delays until the instance is considered unblocked, via methods like ExtendNextUnblock(DateTime).
public Task WaitUnblock(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenA CancellationToken allowing to cancel the awaiting task.
Returns
- Task
A task representing the awaiting of the next unblock time.
Remarks
The cancellationToken must be manually cancelled if
CancelUnblock() is called while awaiting the task.