Table of Contents

Class PooledManualResetValueTaskSource<T>

Namespace
CryptoHives.Foundation.Threading.Pools
Assembly
CryptoHives.Foundation.Threading.dll

An implementation of IValueTaskSource<TResult>.

public sealed class PooledManualResetValueTaskSource<T> : ManualResetValueTaskSource<T>, IValueTaskSource<T>, IValueTaskSource, IResettable

Type Parameters

T
Inheritance
PooledManualResetValueTaskSource<T>
Implements
Inherited Members

Remarks

This class is a sealed implementation of IValueTaskSource<TResult> which 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. In addition, the owner pool can be set to return the instance to the pool when it is no longer needed. This class can be directly used with CryptoHives.Foundation.Threading.Pools.WaiterQueue<T> to store the waiters allocation free. The IResettable interface is implemented to allow resetting the state of the instance for reuse by an implementation of an ObjectPool that uses the DefaultObjectPool<T> implementation.

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.

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

SetOwnerPool(ObjectPool<PooledManualResetValueTaskSource<T>>, object?)

Sets the pool to which the object is returned after it was awaited. Sets the owner of the pooled instance.

public void SetOwnerPool(ObjectPool<PooledManualResetValueTaskSource<T>> ownerPool, object? owner)

Parameters

ownerPool ObjectPool<PooledManualResetValueTaskSource<T>>
owner object

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.

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.