@@ -12,20 +12,10 @@ namespace ServiceStack
12
12
public static class TaskUtils
13
13
{
14
14
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
15
- public static Task < T > FromResult < T > ( T result )
16
- {
17
- var taskSource = new TaskCompletionSource < T > ( ) ;
18
- taskSource . SetResult ( result ) ;
19
- return taskSource . Task ;
20
- }
15
+ public static Task < T > FromResult < T > ( T result ) => Task . FromResult ( result ) ;
21
16
22
17
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
23
- public static Task < T > InTask < T > ( this T result )
24
- {
25
- var taskSource = new TaskCompletionSource < T > ( ) ;
26
- taskSource . SetResult ( result ) ;
27
- return taskSource . Task ;
28
- }
18
+ public static Task < T > InTask < T > ( this T result ) => Task . FromResult ( result ) ;
29
19
30
20
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
31
21
public static Task < T > InTask < T > ( this Exception ex )
@@ -36,15 +26,9 @@ public static Task<T> InTask<T>(this Exception ex)
36
26
}
37
27
38
28
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
39
- public static bool IsSuccess ( this Task task )
40
- {
41
- return ! task . IsFaulted && task . IsCompleted ;
42
- }
29
+ public static bool IsSuccess ( this Task task ) => ! task . IsFaulted && task . IsCompleted ;
43
30
44
- public static Task < To > Cast < From , To > ( this Task < From > task ) where To : From
45
- {
46
- return task . Then ( x => ( To ) x ) ;
47
- }
31
+ public static Task < To > Cast < From , To > ( this Task < From > task ) where To : From => task . Then ( x => ( To ) x ) ;
48
32
49
33
public static TaskScheduler SafeTaskScheduler ( )
50
34
{
0 commit comments