DotNext.Threading by .NET Foundation and Contributors

<PackageReference Include="DotNext.Threading" Version="4.7.4" />

 ValueTaskCompletionSource<T>

Represents the producer side of ValueTask<T>.
public ValueTaskCompletionSource(bool runContinuationsAsynchronously = true)

Initializes a new completion source.

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

public ValueTask<T> CreateTask(TimeSpan timeout, CancellationToken token)

Creates a fresh task linked with this source.

protected virtual Result<T> OnCanceled(CancellationToken token)

Called automatically when cancellation detected.

protected virtual Result<T> OnTimeout()

Called automatically when timeout detected.

public bool TrySetCanceled(short completionToken, CancellationToken token)

Attempts to complete the task unsuccessfully.

public bool TrySetCanceled(object completionData, short completionToken, CancellationToken token)

Attempts to complete the task unsuccessfully.

public bool TrySetException(short completionToken, Exception e)

Attempts to complete the task unsuccessfully.

public bool TrySetException(object completionData, short completionToken, Exception e)

Attempts to complete the task unsuccessfully.

public bool TrySetResult(T value)

Attempts to complete the task sucessfully.

public bool TrySetResult(object completionData, T value)

Attempts to complete the task sucessfully.

public bool TrySetResult(short completionToken, T value)

Attempts to complete the task sucessfully.

public bool TrySetResult(object completionData, short completionToken, T value)

Attempts to complete the task sucessfully.