Show / Hide Table of Contents

Class ValueTaskCompletionSource

Represents the producer side of ValueTask.

Inheritance
object
ManualResetCompletionSource
ValueTaskCompletionSource
Implements
IValueTaskSource
ISupplier<TimeSpan, CancellationToken, ValueTask>
IFunctional
Inherited Members
ManualResetCompletionSource.InitialCompletionToken
ManualResetCompletionSource.Reset()
ManualResetCompletionSource.AfterConsumed()
ManualResetCompletionSource.TrySetException(Exception)
ManualResetCompletionSource.TrySetCanceled(CancellationToken)
ManualResetCompletionSource.TrySetCanceled<TOptions>(TOptions, CancellationToken)
ManualResetCompletionSource.CompletionData
ManualResetCompletionSource.Status
ManualResetCompletionSource.IsCompleted
object.GetType()
object.MemberwiseClone()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: DotNext.Threading.Tasks
Assembly: DotNext.Threading.dll
Syntax
public class ValueTaskCompletionSource : ManualResetCompletionSource, IValueTaskSource, ISupplier<TimeSpan, CancellationToken, ValueTask>, IFunctional
Remarks

See description of ValueTaskCompletionSource<T> for more information about behavior of the completion source.

Constructors

View Source

ValueTaskCompletionSource(bool)

Initializes a new completion source.

Declaration
public ValueTaskCompletionSource(bool runContinuationsAsynchronously = true)
Parameters
Type Name Description
bool runContinuationsAsynchronously

Indicates that continuations must be executed asynchronously.

Methods

View Source

CleanUp()

Resets internal state of this source.

Declaration
protected override void CleanUp()
Overrides
ManualResetCompletionSource.CleanUp()
View Source

CreateLinkedTaskCompletionSource(object?, TimeSpan, CancellationToken)

Creates a linked TaskCompletionSource that can be used cooperatively to complete the task.

Declaration
public TaskCompletionSource CreateLinkedTaskCompletionSource(object? userData, TimeSpan timeout, CancellationToken token)
Parameters
Type Name Description
object userData

The custom data to be associated with the current version of the task.

TimeSpan timeout

The timeout associated with the task.

CancellationToken token

The cancellation token that can be used to cancel the task.

Returns
Type Description
TaskCompletionSource

A linked TaskCompletionSource.

Exceptions
Type Condition
InvalidOperationException

The source is in invalid state.

View Source

CreateTask(TimeSpan, CancellationToken)

Creates a fresh task linked with this source.

Declaration
public ValueTask CreateTask(TimeSpan timeout, CancellationToken token)
Parameters
Type Name Description
TimeSpan timeout

The timeout associated with the task.

CancellationToken token

The cancellation token that can be used to cancel the task.

Returns
Type Description
ValueTask

A fresh uncompleted task.

Remarks

This method must be called after Reset().

Exceptions
Type Condition
ArgumentOutOfRangeException

timeout is less than zero but not equals to InfiniteTimeSpan.

InvalidOperationException

The source is in invalid state.

View Source

GetCancellationException(CancellationToken)

Called automatically when cancellation detected.

Declaration
protected virtual Exception? GetCancellationException(CancellationToken token)
Parameters
Type Name Description
CancellationToken token

The token representing cancellation reason.

Returns
Type Description
Exception

The exception representing task result; or null to complete successfully.

Remarks

By default, this method returns OperationCanceledException as the task result.

View Source

GetTimeoutException()

Called automatically when timeout detected.

Declaration
protected virtual Exception? GetTimeoutException()
Returns
Type Description
Exception

The exception representing task result; or null to complete successfully.

Remarks

By default, this method returns TimeoutException as the task result.

View Source

TrySetException<TOptions>(TOptions, Exception)

Attempts to complete the task unsuccessfully.

Declaration
public override sealed bool TrySetException<TOptions>(TOptions options, Exception e) where TOptions : ManualResetCompletionSource.ICompletionOptions, allows ref struct
Parameters
Type Name Description
TOptions options

The completion options.

Exception e

The exception to be returned to the consumer.

Returns
Type Description
bool

true if the result is completed successfully; false if the task has been canceled or timed out.

Type Parameters
Name Description
TOptions
Overrides
ManualResetCompletionSource.TrySetException<TOptions>(TOptions, Exception)
View Source

TrySetResult()

Attempts to complete the task successfully.

Declaration
public bool TrySetResult()
Returns
Type Description
bool

true if the result is completed successfully; false if the task has been canceled or timed out.

View Source

TrySetResult<TOptions>(TOptions)

Attempts to complete the task successfully.

Declaration
public bool TrySetResult<TOptions>(TOptions options) where TOptions : ManualResetCompletionSource.ICompletionOptions, allows ref struct
Parameters
Type Name Description
TOptions options

The completion options.

Returns
Type Description
bool

true if the result is completed successfully; false if the task has been canceled or timed out.

Type Parameters
Name Description
TOptions

Implements

IValueTaskSource
ISupplier<T1, T2, TResult>
IFunctional

Extension Methods

BasicExtensions.As<T>(T)
BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
BasicExtensions.IsOneOf<T>(T, params ReadOnlySpan<T>)

See Also

ValueTaskCompletionSource<T>
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾