Skip to main content

TaskCompletionSourceExtensions

Provides extension methods for System.Threading.Tasks.TaskCompletionSource%601.

Assembly: ServiceStack.Common.dll​
View Source​
Declaration
public static class TaskCompletionSourceExtensions

Methods​

TryCompleteFromCompletedTask<TResult, TSourceResult>(TaskCompletionSource<TResult>, Task<TSourceResult>)​

Attempts to complete a System.Threading.Tasks.TaskCompletionSource%601, propagating the completion of <code data-dev-comment-type="paramref" class="paramref">task</code>.

View Source​
Declaration
public static bool TryCompleteFromCompletedTask<TResult, TSourceResult>(this TaskCompletionSource<TResult> this, Task<TSourceResult> task)
where TSourceResult : TResult
Returns​

System.Boolean: true if this method completed the task completion source; false if it was already completed.

Parameters​
TypeNameDescription
System.Threading.Tasks.TaskCompletionSource<<TResult>>thisThe task completion source. May not be null.

| | System.Threading.Tasks.Task<<TSourceResult>> | task | The task. May not be null.

|

Type Parameters​
NameDescription
TResultThe type of the result of the target asynchronous operation.
TSourceResultThe type of the result of the source asynchronous operation.

TryCompleteFromCompletedTask<TResult>(TaskCompletionSource<TResult>, Task, Func<TResult>)​

Attempts to complete a System.Threading.Tasks.TaskCompletionSource%601, propagating the completion of <code data-dev-comment-type="paramref" class="paramref">task</code> but using the result value from <code data-dev-comment-type="paramref" class="paramref">resultFunc</code> if the task completed successfully.

View Source​
Declaration
public static bool TryCompleteFromCompletedTask<TResult>(this TaskCompletionSource<TResult> this, Task task, Func<TResult> resultFunc)
Returns​

System.Boolean: true if this method completed the task completion source; false if it was already completed.

Parameters​
TypeNameDescription
System.Threading.Tasks.TaskCompletionSource<<TResult>>thisThe task completion source. May not be null.

| | System.Threading.Tasks.Task | task | The task. May not be null.

| | System.Func<<TResult>> | resultFunc | A delegate that returns the result with which to complete the task completion source, if the task completed successfully. May not be null.

|

Type Parameters​
NameDescription
TResultThe type of the result of the target asynchronous operation.

CreateAsyncTaskSource<TResult>()​

Creates a new TCS for use with async code, and which forces its continuations to execute asynchronously.

View Source​
Declaration
public static TaskCompletionSource<TResult> CreateAsyncTaskSource<TResult>()
Returns​

System.Threading.Tasks.TaskCompletionSource<<TResult>>

Type Parameters​
NameDescription
TResultThe type of the result of the TCS.