Table of Contents

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

owner object

The object to associate with this instance.

Properties

CancellationToken

Gets the CancellationToken associated with the current operation.

public override CancellationToken CancellationToken { get; set; }

Property Value

CancellationToken

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

CancellationTokenRegistration

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

bool

Owner

Gets or sets the owner associated with this instance.

public override object Owner { get; }

Property Value

object

RunContinuationsAsynchronously

Gets or sets whether to force continuations to run asynchronously.

public override bool RunContinuationsAsynchronously { get; set; }

Property Value

bool

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

short

Methods

GetResult(short)

Gets the result of the IValueTaskSource<TResult>.

public override T GetResult(short token)

Parameters

token short

Opaque value that was provided to the ValueTask's constructor.

Returns

T

GetStatus(short)

Gets the status of the current operation.

public override ValueTaskSourceStatus GetStatus(short token)

Parameters

token short

Opaque value that was provided to the ValueTask's constructor.

Returns

ValueTaskSourceStatus

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

continuation Action<object>

The continuation to invoke when the operation has completed.

state object

The state object to pass to continuation when it's invoked.

token short

Opaque value that was provided to the ValueTask's constructor.

flags ValueTaskSourceOnCompletedFlags

The 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

result T

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

ex Exception

SetResult(T)

Signals the completion of an operation, setting the result to T.

public override void SetResult(T result)

Parameters

result T

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

waiter ManualResetValueTaskSource<T>

Returns

bool

Returns true if 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

bool

true if the object was able to reset itself, otherwise false.

Remarks

In general, this method is not expected to be thread-safe.