Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit e0ea39e

Browse files
committed
Use Task.FromResult
1 parent 75d5652 commit e0ea39e

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

src/ServiceStack.Text/TaskUtils.cs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,10 @@ namespace ServiceStack
1212
public static class TaskUtils
1313
{
1414
[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);
2116

2217
[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);
2919

3020
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3121
public static Task<T> InTask<T>(this Exception ex)
@@ -36,15 +26,9 @@ public static Task<T> InTask<T>(this Exception ex)
3626
}
3727

3828
[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;
4330

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);
4832

4933
public static TaskScheduler SafeTaskScheduler()
5034
{

0 commit comments

Comments
 (0)