Table of Contents

Class TaskCompletionSourceExtensions

Namespace
Plugin.BaseTypeExtensions
Assembly
Plugin.BaseTypeExtensions.dll

A family of extension methods that ensure that the TaskCompletionSource is properly cleaned up in the case of a timeout either from the cancellation token or the timeout specified.

Always bear in mind that if the TaskCompletionSource is never completed, its task will never complete. Even though the underlying Task is not actually in a "scheduler" (since TCS tasks are Promise Tasks) never completing tasks, of any type, is generally considered a bug.

public static class TaskCompletionSourceExtensions
Inheritance
TaskCompletionSourceExtensions
Inherited Members

Methods

TrySetResultOrException(TaskCompletionSource, Exception?)

Attempts to complete the TaskCompletionSource with success or an exception.

public static bool TrySetResultOrException(this TaskCompletionSource tcs, Exception? exception = null)

Parameters

tcs TaskCompletionSource

The TaskCompletionSource to complete.

exception Exception

The exception to set if provided. If null, the task will be marked as successfully completed.

Returns

bool

true if the operation was successful; otherwise, false if the task was already completed.

TrySetResultOrException<T>(TaskCompletionSource<T>, T, Exception?)

Attempts to complete the TaskCompletionSource<TResult> with a result or an exception.

public static bool TrySetResultOrException<T>(this TaskCompletionSource<T> tcs, T result, Exception? exception = null)

Parameters

tcs TaskCompletionSource<T>

The TaskCompletionSource<TResult> to complete.

result T

The result to set if no exception is provided.

exception Exception

The exception to set if provided. If null, the result will be used instead.

Returns

bool

true if the operation was successful; otherwise, false if the task was already completed.

Type Parameters

T

The type of the result.