Synchronization
Represents task synchronization and combination methods.
using System;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
namespace DotNext.Threading.Tasks
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public static class Synchronization
{
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
0,
1
})]
public static Result<TResult> GetResult<[System.Runtime.CompilerServices.Nullable(2)] TResult>(this Task<TResult> task, TimeSpan timeout)
{
try {
return task.Wait(timeout) ? new Result<TResult>(task.Result) : new Result<TResult>((Exception)new TimeoutException());
} catch (Exception error) {
return new Result<TResult>(error);
}
}
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
0,
1
})]
public static Result<TResult> GetResult<[System.Runtime.CompilerServices.Nullable(2)] TResult>(this Task<TResult> task, CancellationToken token)
{
try {
task.Wait(token);
return task.Result;
} catch (Exception error) {
return new Result<TResult>(error);
}
}
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
0,
2
})]
public static Result<dynamic> GetResult(this Task task, CancellationToken token)
{
try {
task.Wait(token);
return new Result<object>(new DynamicTaskAwaitable.Awaiter(task, false).GetRawResult());
} catch (Exception error) {
return new Result<object>(error);
}
}
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
0,
2
})]
public static Result<dynamic> GetResult(this Task task, TimeSpan timeout)
{
try {
if (!task.Wait(timeout))
return new Result<object>(new TimeoutException());
return new Result<object>(new DynamicTaskAwaitable.Awaiter(task, false).GetRawResult());
} catch (Exception error) {
return new Result<object>(error);
}
}
[AsyncStateMachine(typeof(<WhenAll>d__4<, >))]
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0,
1,
1
})]
public static Task<(T1, T2)> WhenAll<[System.Runtime.CompilerServices.Nullable(2)] T1, [System.Runtime.CompilerServices.Nullable(2)] T2>(Task<T1> task1, Task<T2> task2)
{
<WhenAll>d__4<T1, T2> stateMachine = default(<WhenAll>d__4<T1, T2>);
stateMachine.<>t__builder = AsyncTaskMethodBuilder<(T1, T2)>.Create();
stateMachine.task1 = task1;
stateMachine.task2 = task2;
stateMachine.<>1__state = -1;
stateMachine.<>t__builder.Start(ref stateMachine);
return stateMachine.<>t__builder.Task;
}
[AsyncStateMachine(typeof(<WhenAll>d__5<, , >))]
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0,
1,
1,
1
})]
public static Task<(T1, T2, T3)> WhenAll<[System.Runtime.CompilerServices.Nullable(2)] T1, [System.Runtime.CompilerServices.Nullable(2)] T2, [System.Runtime.CompilerServices.Nullable(2)] T3>(Task<T1> task1, Task<T2> task2, Task<T3> task3)
{
<WhenAll>d__5<T1, T2, T3> stateMachine = default(<WhenAll>d__5<T1, T2, T3>);
stateMachine.<>t__builder = AsyncTaskMethodBuilder<(T1, T2, T3)>.Create();
stateMachine.task1 = task1;
stateMachine.task2 = task2;
stateMachine.task3 = task3;
stateMachine.<>1__state = -1;
stateMachine.<>t__builder.Start(ref stateMachine);
return stateMachine.<>t__builder.Task;
}
[AsyncStateMachine(typeof(<WhenAll>d__6<, , , >))]
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0,
1,
1,
1,
1
})]
public static Task<(T1, T2, T3, T4)> WhenAll<[System.Runtime.CompilerServices.Nullable(2)] T1, [System.Runtime.CompilerServices.Nullable(2)] T2, [System.Runtime.CompilerServices.Nullable(2)] T3, [System.Runtime.CompilerServices.Nullable(2)] T4>(Task<T1> task1, Task<T2> task2, Task<T3> task3, Task<T4> task4)
{
<WhenAll>d__6<T1, T2, T3, T4> stateMachine = default(<WhenAll>d__6<T1, T2, T3, T4>);
stateMachine.<>t__builder = AsyncTaskMethodBuilder<(T1, T2, T3, T4)>.Create();
stateMachine.task1 = task1;
stateMachine.task2 = task2;
stateMachine.task3 = task3;
stateMachine.task4 = task4;
stateMachine.<>1__state = -1;
stateMachine.<>t__builder.Start(ref stateMachine);
return stateMachine.<>t__builder.Task;
}
[AsyncStateMachine(typeof(<WhenAll>d__7<, , , , >))]
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
1,
0,
1,
1,
1,
1,
1
})]
public static Task<(T1, T2, T3, T4, T5)> WhenAll<[System.Runtime.CompilerServices.Nullable(2)] T1, [System.Runtime.CompilerServices.Nullable(2)] T2, [System.Runtime.CompilerServices.Nullable(2)] T3, [System.Runtime.CompilerServices.Nullable(2)] T4, [System.Runtime.CompilerServices.Nullable(2)] T5>(Task<T1> task1, Task<T2> task2, Task<T3> task3, Task<T4> task4, Task<T5> task5)
{
<WhenAll>d__7<T1, T2, T3, T4, T5> stateMachine = default(<WhenAll>d__7<T1, T2, T3, T4, T5>);
stateMachine.<>t__builder = AsyncTaskMethodBuilder<(T1, T2, T3, T4, T5)>.Create();
stateMachine.task1 = task1;
stateMachine.task2 = task2;
stateMachine.task3 = task3;
stateMachine.task4 = task4;
stateMachine.task5 = task5;
stateMachine.<>1__state = -1;
stateMachine.<>t__builder.Start(ref stateMachine);
return stateMachine.<>t__builder.Task;
}
}
}