Class Synchronization
Represents task synchronization methods.
Inherited Members
Namespace: DotNext.Threading.Tasks
Assembly: DotNext.dll
Syntax
public static class Synchronization
Methods
| Edit this page View SourceGetResult(Task, CancellationToken)
Gets task result synchronously.
Declaration
public static Result<dynamic?> GetResult(this Task task, CancellationToken token)
Parameters
| Type | Name | Description |
|---|---|---|
| Task | task | The task to synchronize. |
| CancellationToken | token | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Result<object> | Task result; or Value returned from Value if |
GetResult(Task, TimeSpan)
Gets task result synchronously.
Declaration
public static Result<dynamic?> GetResult(this Task task, TimeSpan timeout)
Parameters
| Type | Name | Description |
|---|---|---|
| Task | task | The task to synchronize. |
| TimeSpan | timeout | Synchronization timeout. |
Returns
| Type | Description |
|---|---|
| Result<object> | Task result; or Value returned from Value if |
Exceptions
| Type | Condition |
|---|---|
| TimeoutException | Task is not completed. |
GetResult<TResult>(Task<TResult>, CancellationToken)
Gets task result synchronously.
Declaration
public static Result<TResult> GetResult<TResult>(this Task<TResult> task, CancellationToken token)
Parameters
| Type | Name | Description |
|---|---|---|
| Task<TResult> | task | The task to synchronize. |
| CancellationToken | token | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Result<TResult> | Task result. |
Type Parameters
| Name | Description |
|---|---|
| TResult | Type of task result. |
GetResult<TResult>(Task<TResult>, TimeSpan)
Gets task result synchronously.
Declaration
public static Result<TResult> GetResult<TResult>(this Task<TResult> task, TimeSpan timeout)
Parameters
| Type | Name | Description |
|---|---|---|
| Task<TResult> | task | The task to synchronize. |
| TimeSpan | timeout | Synchronization timeout. |
Returns
| Type | Description |
|---|---|
| Result<TResult> | Task result. |
Type Parameters
| Name | Description |
|---|---|
| TResult | Type of task result. |
Exceptions
| Type | Condition |
|---|---|
| TimeoutException | Task is not completed. |
TryGetResult<TResult>(Task<TResult>?)
Attempts to get the result of the task if it is completed.
Declaration
public static Result<TResult>? TryGetResult<TResult>(this Task<TResult>? task)
Parameters
| Type | Name | Description |
|---|---|---|
| Task<TResult> | task | The task to synchronize. |
Returns
| Type | Description |
|---|---|
| Result<TResult>? | Task result; or null if |
Type Parameters
| Name | Description |
|---|---|
| TResult | Type of task result. |
Wait(in ValueTask)
Waits for the task synchronously.
Declaration
public static void Wait(this in ValueTask task)
Parameters
| Type | Name | Description |
|---|---|---|
| ValueTask | task | The task to wait. |
Remarks
In contrast to Wait() this method doesn't use wait handles.
Wait<T>(in ValueTask<T>)
Waits for the task synchronously.
Declaration
public static T Wait<T>(this in ValueTask<T> task)
Parameters
| Type | Name | Description |
|---|---|---|
| ValueTask<T> | task | The task to wait. |
Returns
| Type | Description |
|---|---|
| T |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the task result. |
Remarks
In contrast to Wait() this method doesn't use wait handles.
WhenAll(ValueTask, ValueTask)
Creates a task that will complete when all the passed tasks have completed.
Declaration
public static ValueTask WhenAll(ValueTask task1, ValueTask task2)
Parameters
| Type | Name | Description |
|---|---|---|
| ValueTask | task1 | The first task to await. |
| ValueTask | task2 | The second task to await. |
Returns
| Type | Description |
|---|---|
| ValueTask | A task that represents the completion of all the supplied tasks. |
Remarks
This method avoid memory allocation in the managed heap if all tasks are completed (or will be soon) at the time of calling this method.
WhenAll(ValueTask, ValueTask, ValueTask)
Creates a task that will complete when all the passed tasks have completed.
Declaration
public static ValueTask WhenAll(ValueTask task1, ValueTask task2, ValueTask task3)
Parameters
| Type | Name | Description |
|---|---|---|
| ValueTask | task1 | The first task to await. |
| ValueTask | task2 | The second task to await. |
| ValueTask | task3 | The third task to await. |
Returns
| Type | Description |
|---|---|
| ValueTask | A task that represents the completion of all the supplied tasks. |
Remarks
This method avoid memory allocation in the managed heap if all tasks are completed (or will be soon) at the time of calling this method.
WhenAll(ValueTask, ValueTask, ValueTask, ValueTask)
Creates a task that will complete when all the passed tasks have completed.
Declaration
public static ValueTask WhenAll(ValueTask task1, ValueTask task2, ValueTask task3, ValueTask task4)
Parameters
| Type | Name | Description |
|---|---|---|
| ValueTask | task1 | The first task to await. |
| ValueTask | task2 | The second task to await. |
| ValueTask | task3 | The third task to await. |
| ValueTask | task4 | The fourth task to await. |
Returns
| Type | Description |
|---|---|
| ValueTask | A task that represents the completion of all the supplied tasks. |
Remarks
This method avoid memory allocation in the managed heap if all tasks are completed (or will be soon) at the time of calling this method.
WhenAll(ValueTask, ValueTask, ValueTask, ValueTask, ValueTask)
Creates a task that will complete when all the passed tasks have completed.
Declaration
public static ValueTask WhenAll(ValueTask task1, ValueTask task2, ValueTask task3, ValueTask task4, ValueTask task5)
Parameters
| Type | Name | Description |
|---|---|---|
| ValueTask | task1 | The first task to await. |
| ValueTask | task2 | The second task to await. |
| ValueTask | task3 | The third task to await. |
| ValueTask | task4 | The fourth task to await. |
| ValueTask | task5 | The fifth task to await. |
Returns
| Type | Description |
|---|---|
| ValueTask | A task that represents the completion of all the supplied tasks. |
Remarks
This method avoid memory allocation in the managed heap if all tasks are completed (or will be soon) at the time of calling this method.
WhenAll<T1, T2>(Task<T1>, Task<T2>)
Creates a task that will complete when all of the passed tasks have completed.
Declaration
public static Task<(Result<T1>, Result<T2>)> WhenAll<T1, T2>(Task<T1> task1, Task<T2> task2)
Parameters
| Type | Name | Description |
|---|---|---|
| Task<T1> | task1 | The first task to await. |
| Task<T2> | task2 | The second task to await. |
Returns
| Type | Description |
|---|---|
| Task<(Result<T1>, Result<T2>)> | The task containing results of both tasks. |
Type Parameters
| Name | Description |
|---|---|
| T1 | The type of the first task. |
| T2 | The type of the second task. |
WhenAll<T1, T2>(ValueTask<T1>, ValueTask<T2>)
Creates a task that will complete when all the passed tasks have completed.
Declaration
public static ValueTask<(Result<T1>, Result<T2>)> WhenAll<T1, T2>(ValueTask<T1> task1, ValueTask<T2> task2)
Parameters
| Type | Name | Description |
|---|---|---|
| ValueTask<T1> | task1 | The first task to await. |
| ValueTask<T2> | task2 | The second task to await. |
Returns
| Type | Description |
|---|---|
| ValueTask<(Result<T1>, Result<T2>)> | A task containing results of both tasks. |
Type Parameters
| Name | Description |
|---|---|
| T1 | The type of the first task. |
| T2 | The type of the second task. |
Remarks
This method avoid memory allocation in the managed heap if all tasks are completed (or will be soon) at the time of calling this method.
WhenAll<T1, T2, T3>(Task<T1>, Task<T2>, Task<T3>)
Creates a task that will complete when all of the passed tasks have completed.
Declaration
public static Task<(Result<T1>, Result<T2>, Result<T3>)> WhenAll<T1, T2, T3>(Task<T1> task1, Task<T2> task2, Task<T3> task3)
Parameters
| Type | Name | Description |
|---|---|---|
| Task<T1> | task1 | The first task to await. |
| Task<T2> | task2 | The second task to await. |
| Task<T3> | task3 | The third task to await. |
Returns
| Type | Description |
|---|---|
| Task<(Result<T1>, Result<T2>, Result<T3>)> | The task containing results of all tasks. |
Type Parameters
| Name | Description |
|---|---|
| T1 | The type of the first task. |
| T2 | The type of the second task. |
| T3 | The type of the third task. |
WhenAll<T1, T2, T3>(ValueTask<T1>, ValueTask<T2>, ValueTask<T3>)
Creates a task that will complete when all the passed tasks have completed.
Declaration
public static ValueTask<(Result<T1>, Result<T2>, Result<T3>)> WhenAll<T1, T2, T3>(ValueTask<T1> task1, ValueTask<T2> task2, ValueTask<T3> task3)
Parameters
| Type | Name | Description |
|---|---|---|
| ValueTask<T1> | task1 | The first task to await. |
| ValueTask<T2> | task2 | The second task to await. |
| ValueTask<T3> | task3 | The third task to await. |
Returns
| Type | Description |
|---|---|
| ValueTask<(Result<T1>, Result<T2>, Result<T3>)> | A task containing results of all tasks. |
Type Parameters
| Name | Description |
|---|---|
| T1 | The type of the first task. |
| T2 | The type of the second task. |
| T3 | The type of the third task. |
Remarks
This method avoid memory allocation in the managed heap if all tasks are completed (or will be soon) at the time of calling this method.
WhenAll<T1, T2, T3, T4>(Task<T1>, Task<T2>, Task<T3>, Task<T4>)
Creates a task that will complete when all the passed tasks have completed.
Declaration
public static Task<(Result<T1>, Result<T2>, Result<T3>, Result<T4>)> WhenAll<T1, T2, T3, T4>(Task<T1> task1, Task<T2> task2, Task<T3> task3, Task<T4> task4)
Parameters
| Type | Name | Description |
|---|---|---|
| Task<T1> | task1 | The first task to await. |
| Task<T2> | task2 | The second task to await. |
| Task<T3> | task3 | The third task to await. |
| Task<T4> | task4 | The fourth task to await. |
Returns
| Type | Description |
|---|---|
| Task<(Result<T1>, Result<T2>, Result<T3>, Result<T4>)> | The task containing results of all tasks. |
Type Parameters
| Name | Description |
|---|---|
| T1 | The type of the first task. |
| T2 | The type of the second task. |
| T3 | The type of the third task. |
| T4 | The type of the fourth task. |
WhenAll<T1, T2, T3, T4>(ValueTask<T1>, ValueTask<T2>, ValueTask<T3>, ValueTask<T4>)
Creates a task that will complete when all the passed tasks have completed.
Declaration
public static ValueTask<(Result<T1>, Result<T2>, Result<T3>, Result<T4>)> WhenAll<T1, T2, T3, T4>(ValueTask<T1> task1, ValueTask<T2> task2, ValueTask<T3> task3, ValueTask<T4> task4)
Parameters
| Type | Name | Description |
|---|---|---|
| ValueTask<T1> | task1 | The first task to await. |
| ValueTask<T2> | task2 | The second task to await. |
| ValueTask<T3> | task3 | The third task to await. |
| ValueTask<T4> | task4 | The fourth task to await. |
Returns
| Type | Description |
|---|---|
| ValueTask<(Result<T1>, Result<T2>, Result<T3>, Result<T4>)> | A task containing results of all tasks. |
Type Parameters
| Name | Description |
|---|---|
| T1 | The type of the first task. |
| T2 | The type of the second task. |
| T3 | The type of the third task. |
| T4 | The type of the fourth task. |
Remarks
This method avoid memory allocation in the managed heap if all tasks are completed (or will be soon) at the time of calling this method.
WhenAll<T1, T2, T3, T4, T5>(Task<T1>, Task<T2>, Task<T3>, Task<T4>, Task<T5>)
Creates a task that will complete when all the passed tasks have completed.
Declaration
public static Task<(Result<T1>, Result<T2>, Result<T3>, Result<T4>, Result<T5>)> WhenAll<T1, T2, T3, T4, T5>(Task<T1> task1, Task<T2> task2, Task<T3> task3, Task<T4> task4, Task<T5> task5)
Parameters
| Type | Name | Description |
|---|---|---|
| Task<T1> | task1 | The first task to await. |
| Task<T2> | task2 | The second task to await. |
| Task<T3> | task3 | The third task to await. |
| Task<T4> | task4 | The fourth task to await. |
| Task<T5> | task5 | The fifth task to await. |
Returns
| Type | Description |
|---|---|
| Task<(Result<T1>, Result<T2>, Result<T3>, Result<T4>, Result<T5>)> | The task containing results of all tasks. |
Type Parameters
| Name | Description |
|---|---|
| T1 | The type of the first task. |
| T2 | The type of the second task. |
| T3 | The type of the third task. |
| T4 | The type of the fourth task. |
| T5 | The type of the fifth task. |
WhenAll<T1, T2, T3, T4, T5>(ValueTask<T1>, ValueTask<T2>, ValueTask<T3>, ValueTask<T4>, ValueTask<T5>)
Creates a task that will complete when all the passed tasks have completed.
Declaration
public static ValueTask<(Result<T1>, Result<T2>, Result<T3>, Result<T4>, Result<T5>)> WhenAll<T1, T2, T3, T4, T5>(ValueTask<T1> task1, ValueTask<T2> task2, ValueTask<T3> task3, ValueTask<T4> task4, ValueTask<T5> task5)
Parameters
| Type | Name | Description |
|---|---|---|
| ValueTask<T1> | task1 | The first task to await. |
| ValueTask<T2> | task2 | The second task to await. |
| ValueTask<T3> | task3 | The third task to await. |
| ValueTask<T4> | task4 | The fourth task to await. |
| ValueTask<T5> | task5 | The fifth task to await. |
Returns
| Type | Description |
|---|---|
| ValueTask<(Result<T1>, Result<T2>, Result<T3>, Result<T4>, Result<T5>)> | A task containing results of all tasks. |
Type Parameters
| Name | Description |
|---|---|
| T1 | The type of the first task. |
| T2 | The type of the second task. |
| T3 | The type of the third task. |
| T4 | The type of the fourth task. |
| T5 | The type of the fifth task. |
Remarks
This method avoid memory allocation in the managed heap if all tasks are completed (or will be soon) at the time of calling this method.