Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
AsyncHelper.cs
Go to the documentation of this file.
2
3namespace System.Xml;
4
5internal static class AsyncHelper
6{
7 public static readonly Task<bool> DoneTaskTrue = Task.FromResult(result: true);
8
9 public static readonly Task<bool> DoneTaskFalse = Task.FromResult(result: false);
10
11 public static readonly Task<int> DoneTaskZero = Task.FromResult(0);
12
13 public static bool IsSuccess(this Task task)
14 {
15 return task.IsCompletedSuccessfully;
16 }
17
18 public static Task CallVoidFuncWhenFinishAsync<TArg>(this Task task, Action<TArg> func, TArg arg)
19 {
20 if (task.IsSuccess())
21 {
22 func(arg);
23 return Task.CompletedTask;
24 }
25 return task.CallVoidFuncWhenFinishCoreAsync(func, arg);
26 }
27
28 private static async Task CallVoidFuncWhenFinishCoreAsync<TArg>(this Task task, Action<TArg> func, TArg arg)
29 {
30 await task.ConfigureAwait(continueOnCapturedContext: false);
31 func(arg);
32 }
33
35 {
36 if (!task.IsSuccess())
37 {
38 return task.ReturnTrueTaskWhenFinishCoreAsync();
39 }
40 return DoneTaskTrue;
41 }
42
44 {
45 await task.ConfigureAwait(continueOnCapturedContext: false);
46 return true;
47 }
48
50 {
51 if (!task.IsSuccess())
52 {
54 }
55 return func(arg);
56 }
57
59 {
60 await task.ConfigureAwait(continueOnCapturedContext: false);
61 await func(arg).ConfigureAwait(continueOnCapturedContext: false);
62 }
63
65 {
66 if (!task.IsSuccess())
67 {
68 return task.CallBoolTaskFuncWhenFinishCoreAsync(func, arg);
69 }
70 return func(arg);
71 }
72
74 {
75 await task.ConfigureAwait(continueOnCapturedContext: false);
76 return await func(arg).ConfigureAwait(continueOnCapturedContext: false);
77 }
78
80 {
81 if (task.IsSuccess())
82 {
83 if (!task.Result)
84 {
85 return func(arg);
86 }
87 return DoneTaskTrue;
88 }
90 }
91
93 {
94 if (await task.ConfigureAwait(continueOnCapturedContext: false))
95 {
96 return true;
97 }
98 return await func(arg).ConfigureAwait(continueOnCapturedContext: false);
99 }
100}
static Task CompletedTask
Definition Task.cs:1120
static async Task< bool > ContinueBoolTaskFuncWhenFalseCoreAsync< TArg >(Task< bool > task, Func< TArg, Task< bool > > func, TArg arg)
static bool IsSuccess(this Task task)
static Task< bool > CallBoolTaskFuncWhenFinishAsync< TArg >(this Task task, Func< TArg, Task< bool > > func, TArg arg)
static async Task< bool > ReturnTrueTaskWhenFinishCoreAsync(this Task task)
static readonly Task< int > DoneTaskZero
static readonly Task< bool > DoneTaskTrue
Definition AsyncHelper.cs:7
static Task< bool > ContinueBoolTaskFuncWhenFalseAsync< TArg >(this Task< bool > task, Func< TArg, Task< bool > > func, TArg arg)
static Task CallTaskFuncWhenFinishAsync< TArg >(this Task task, Func< TArg, Task > func, TArg arg)
static async Task CallVoidFuncWhenFinishCoreAsync< TArg >(this Task task, Action< TArg > func, TArg arg)
static readonly Task< bool > DoneTaskFalse
Definition AsyncHelper.cs:9
static Task< bool > ReturnTrueTaskWhenFinishAsync(this Task task)
static Task CallVoidFuncWhenFinishAsync< TArg >(this Task task, Action< TArg > func, TArg arg)
static async Task CallTaskFuncWhenFinishCoreAsync< TArg >(Task task, Func< TArg, Task > func, TArg arg)
static async Task< bool > CallBoolTaskFuncWhenFinishCoreAsync< TArg >(this Task task, Func< TArg, Task< bool > > func, TArg arg)