forked from ServiceStack/ServiceStack.Text
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskResult.cs
More file actions
45 lines (38 loc) · 1.21 KB
/
TaskResult.cs
File metadata and controls
45 lines (38 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (c) ServiceStack, Inc. All Rights Reserved.
// License: https://raw.github.com/ServiceStack/ServiceStack/master/license.txt
using System.Threading.Tasks;
namespace ServiceStack
{
public static class TaskResult
{
public static Task<int> Zero;
public static Task<int> One;
public static readonly Task<bool> True;
public static readonly Task<bool> False;
public static readonly Task Finished;
public static readonly Task Canceled;
static TaskResult()
{
Finished = ((object)null).InTask();
True = true.InTask();
False = false.InTask();
Zero = 0.InTask();
One = 1.InTask();
var tcs = new TaskCompletionSource<object>();
tcs.SetCanceled();
Canceled = tcs.Task;
}
}
internal class TaskResult<T>
{
public static readonly Task<T> Canceled;
public static readonly Task<T> Default;
static TaskResult()
{
Default = ((T)typeof(T).GetDefaultValue()).InTask();
var tcs = new TaskCompletionSource<T>();
tcs.SetCanceled();
Canceled = tcs.Task;
}
}
}