root / trunk / Libraries / ParallelExtensionsExtras / Extensions / CompletedTask.cs @ d17258c2
History | View | Annotate | Download (1.3 kB)
1 |
//-------------------------------------------------------------------------- |
---|---|
2 |
// |
3 |
// Copyright (c) Microsoft Corporation. All rights reserved. |
4 |
// |
5 |
// File: CompletedTask.cs |
6 |
// |
7 |
//-------------------------------------------------------------------------- |
8 |
|
9 |
namespace System.Threading.Tasks |
10 |
{ |
11 |
/// <summary>Provides access to an already completed task.</summary> |
12 |
/// <remarks>A completed task can be useful for using ContinueWith overloads where there aren't StartNew equivalents.</remarks> |
13 |
public static class CompletedTask |
14 |
{ |
15 |
/// <summary>Gets a completed Task.</summary> |
16 |
public readonly static Task Default = CompletedTask<object>.Default; |
17 |
} |
18 |
|
19 |
/// <summary>Provides access to an already completed task.</summary> |
20 |
/// <remarks>A completed task can be useful for using ContinueWith overloads where there aren't StartNew equivalents.</remarks> |
21 |
public static class CompletedTask<TResult> |
22 |
{ |
23 |
/// <summary>Initializes a Task.</summary> |
24 |
static CompletedTask() |
25 |
{ |
26 |
var tcs = new TaskCompletionSource<TResult>(); |
27 |
tcs.TrySetResult(default(TResult)); |
28 |
Default = tcs.Task; |
29 |
} |
30 |
|
31 |
/// <summary>Gets a completed Task.</summary> |
32 |
public readonly static Task<TResult> Default; |
33 |
} |
34 |
} |