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
tcsTaskCompletionSourceThe TaskCompletionSource to complete.
exceptionExceptionThe exception to set if provided. If null, the task will be marked as successfully completed.
Returns
- bool
trueif the operation was successful; otherwise,falseif 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
tcsTaskCompletionSource<T>The TaskCompletionSource<TResult> to complete.
resultTThe result to set if no exception is provided.
exceptionExceptionThe exception to set if provided. If null, the result will be used instead.
Returns
- bool
trueif the operation was successful; otherwise,falseif the task was already completed.
Type Parameters
TThe type of the result.