-
Notifications
You must be signed in to change notification settings - Fork 5k
/
CompletedTask.cs
31 lines (28 loc) · 1.17 KB
/
CompletedTask.cs
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
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
//
namespace System.Threading.Tasks
{
/// <summary>Provides access to an already completed task.</summary>
/// <remarks>A completed task can be useful for using ContinueWith overloads where there aren't StartNew equivalents.</remarks>
public static class CompletedTask
{
/// <summary>Gets a completed Task.</summary>
public readonly static Task Default = CompletedTask<object>.Default;
}
/// <summary>Provides access to an already completed task.</summary>
/// <remarks>A completed task can be useful for using ContinueWith overloads where there aren't StartNew equivalents.</remarks>
public static class CompletedTask<TResult>
{
/// <summary>Initializes a Task.</summary>
static CompletedTask()
{
var tcs = new TaskCompletionSource<TResult>();
tcs.TrySetResult(default);
Default = tcs.Task;
}
/// <summary>Gets a completed Task.</summary>
public readonly static Task<TResult> Default;
}
}