Class LocalManualResetValueTaskSource<T>
- Namespace
- CryptoHives.Foundation.Threading.Pools
- Assembly
- CryptoHives.Foundation.Threading.dll
An implementation of IValueTaskSource<TResult>.
public sealed class LocalManualResetValueTaskSource<T> : ManualResetValueTaskSource<T>, IValueTaskSource<T>, IValueTaskSource, IResettable
Type Parameters
T
- Inheritance
-
LocalManualResetValueTaskSource<T>
- Implements
- Inherited Members
Remarks
This class is a sealed implementation of IValueTaskSource<TResult> and provides methods to manage the lifecycle of a task-like operation. It allows resetting and signaling the completion of the operation, and supports querying the status and retrieving the result. It is used as a local reusable value task source to minimize allocations. This class can be directly used with CryptoHives.Foundation.Threading.Pools.WaiterQueue<T> to store the waiters allocation free.
Constructors
LocalManualResetValueTaskSource(object)
Initializes a new instance of the LocalManualResetValueTaskSource class and associates it with the specified owner class. The owner is typically the class which contains the reference to this ValueTaskSource.
public LocalManualResetValueTaskSource(object owner)
Parameters
ownerobjectThe object to associate with this instance.
Properties
CancellationToken
Gets the CancellationToken associated with the current operation.
public override CancellationToken CancellationToken { get; set; }
Property Value
Remarks
This token may be cancelled during long-running operations.
CancellationTokenRegistration
Gets the CancellationTokenRegistration associated with the current operation.
public override CancellationTokenRegistration CancellationTokenRegistration { get; set; }
Property Value
Remarks
Use this token to unregister from cancellation requests.
InUse
Gets whether the value task source is currently in use.
public bool InUse { get; }
Property Value
Owner
Gets or sets the owner associated with this instance.
public override object Owner { get; }
Property Value
RunContinuationsAsynchronously
Gets or sets whether to force continuations to run asynchronously.
public override bool RunContinuationsAsynchronously { get; set; }
Property Value
Remarks
Continuations may run asynchronously if this is false, but they'll never run synchronously if this is true.
TimeoutTimer
Gets or sets the TimeoutTimer used to enforce a timeout on the wait operation.
public override ITimer? TimeoutTimer { get; set; }
Property Value
- ITimer
Remarks
Set to a non-null value when the waiter is created with a timeout. The timer is disposed and cleared by TryReset() when the waiter is recycled.
Version
Gets the version number of the current instance.
public override short Version { get; }
Property Value
Methods
GetResult(short)
Gets the result of the IValueTaskSource<TResult>.
public override T GetResult(short token)
Parameters
Returns
- T
GetStatus(short)
Gets the status of the current operation.
public override ValueTaskSourceStatus GetStatus(short token)
Parameters
Returns
OnCompleted(Action<object?>, object?, short, ValueTaskSourceOnCompletedFlags)
Schedules the continuation action for this IValueTaskSource<TResult>.
public override void OnCompleted(Action<object?> continuation, object? state, short token, ValueTaskSourceOnCompletedFlags flags)
Parameters
continuationAction<object>The continuation to invoke when the operation has completed.
stateobjectThe state object to pass to
continuationwhen it's invoked.tokenshortOpaque value that was provided to the ValueTask's constructor.
flagsValueTaskSourceOnCompletedFlagsThe flags describing the behavior of the continuation.
SetChainResult(T)
Signals the completion of an operation, setting the result to T for a chain of operations.
public override void SetChainResult(T result)
Parameters
resultT
Remarks
This method is typically used to indicate that a chain of asynchronous operations has completed successfully.
SetException(Exception)
Sets the specified exception to be associated with the current operation.
public override void SetException(Exception ex)
Parameters
exException
SetResult(T)
Signals the completion of an operation, setting the result to T.
public override void SetResult(T result)
Parameters
resultT
Remarks
This method is typically used to indicate that an asynchronous operation has completed successfully.
TryGetValueTaskSource(out ManualResetValueTaskSource<T>)
Tries to get ownership of the local value task source.
public bool TryGetValueTaskSource(out ManualResetValueTaskSource<T> waiter)
Parameters
waiterManualResetValueTaskSource<T>
Returns
- bool
Returns
trueif ownership was acquired; otherwise,false.
TryReset()
Reset the object to a neutral state, semantically similar to when the object was first constructed.
public override bool TryReset()
Returns
Remarks
In general, this method is not expected to be thread-safe.