diff options
author | Stephen Toub <stoub@microsoft.com> | 2018-03-01 16:59:32 +0300 |
---|---|---|
committer | Stephen Toub <stoub@microsoft.com> | 2018-03-02 01:14:55 +0300 |
commit | d6fb9d46bcc46b25e3453077fd6a5e9cdd8c641a (patch) | |
tree | 11ca4de679807bf2d901772c12cf7ff3804f19db /src | |
parent | b5fd1dae2c1268839ff624a3aa34029c43d6f42b (diff) |
Adjust System.Threading.Tasks.Extensions for IValueTaskSource
Signed-off-by: dotnet-bot-corefx-mirror <dotnet-bot@microsoft.com>
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
Diffstat (limited to 'src')
4 files changed, 15 insertions, 24 deletions
diff --git a/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConfiguredValueTaskAwaitable.cs b/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConfiguredValueTaskAwaitable.cs index 65d3d5670..e85e42e5f 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConfiguredValueTaskAwaitable.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConfiguredValueTaskAwaitable.cs @@ -71,7 +71,7 @@ namespace System.Runtime.CompilerServices } else { - Task.CompletedTask.ConfigureAwait(_value.ContinueOnCapturedContext).GetAwaiter().OnCompleted(continuation); + ValueTask.CompletedTask.ConfigureAwait(_value.ContinueOnCapturedContext).GetAwaiter().OnCompleted(continuation); } } @@ -89,7 +89,7 @@ namespace System.Runtime.CompilerServices } else { - Task.CompletedTask.ConfigureAwait(_value.ContinueOnCapturedContext).GetAwaiter().UnsafeOnCompleted(continuation); + ValueTask.CompletedTask.ConfigureAwait(_value.ContinueOnCapturedContext).GetAwaiter().UnsafeOnCompleted(continuation); } } @@ -173,7 +173,7 @@ namespace System.Runtime.CompilerServices } else { - Task.CompletedTask.ConfigureAwait(_value.ContinueOnCapturedContext).GetAwaiter().OnCompleted(continuation); + ValueTask.CompletedTask.ConfigureAwait(_value.ContinueOnCapturedContext).GetAwaiter().OnCompleted(continuation); } } @@ -191,7 +191,7 @@ namespace System.Runtime.CompilerServices } else { - Task.CompletedTask.ConfigureAwait(_value.ContinueOnCapturedContext).GetAwaiter().UnsafeOnCompleted(continuation); + ValueTask.CompletedTask.ConfigureAwait(_value.ContinueOnCapturedContext).GetAwaiter().UnsafeOnCompleted(continuation); } } diff --git a/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ValueTaskAwaiter.cs b/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ValueTaskAwaiter.cs index 0414a05a0..2dad5d5f9 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ValueTaskAwaiter.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ValueTaskAwaiter.cs @@ -58,7 +58,7 @@ namespace System.Runtime.CompilerServices } else { - Task.CompletedTask.GetAwaiter().OnCompleted(continuation); + ValueTask.CompletedTask.GetAwaiter().OnCompleted(continuation); } } @@ -75,7 +75,7 @@ namespace System.Runtime.CompilerServices } else { - Task.CompletedTask.GetAwaiter().UnsafeOnCompleted(continuation); + ValueTask.CompletedTask.GetAwaiter().UnsafeOnCompleted(continuation); } } @@ -149,7 +149,7 @@ namespace System.Runtime.CompilerServices } else { - Task.CompletedTask.GetAwaiter().OnCompleted(continuation); + ValueTask.CompletedTask.GetAwaiter().OnCompleted(continuation); } } @@ -166,7 +166,7 @@ namespace System.Runtime.CompilerServices } else { - Task.CompletedTask.GetAwaiter().UnsafeOnCompleted(continuation); + ValueTask.CompletedTask.GetAwaiter().UnsafeOnCompleted(continuation); } } diff --git a/src/System.Private.CoreLib/shared/System/Threading/Tasks/Sources/IValueTaskSource.cs b/src/System.Private.CoreLib/shared/System/Threading/Tasks/Sources/IValueTaskSource.cs index 3c1e8830a..e411146a1 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/Tasks/Sources/IValueTaskSource.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/Tasks/Sources/IValueTaskSource.cs @@ -23,8 +23,7 @@ namespace System.Threading.Tasks.Sources /// </summary> UseSchedulingContext = 0x1, /// <summary> - /// Set if OnCompleted should capture the current <see cref="ExecutionContext"/> and use it to - /// <see cref="ExecutionContext.Run"/> the continuation. + /// Set if OnCompleted should capture the current ExecutionContext and use it to run the continuation. /// </summary> FlowExecutionContext = 0x2, } diff --git a/src/System.Private.CoreLib/shared/System/Threading/Tasks/ValueTask.cs b/src/System.Private.CoreLib/shared/System/Threading/Tasks/ValueTask.cs index 6c45ed656..c46a6cbc1 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/Tasks/ValueTask.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/Tasks/ValueTask.cs @@ -25,9 +25,11 @@ namespace System.Threading.Tasks [StructLayout(LayoutKind.Auto)] public readonly struct ValueTask : IEquatable<ValueTask> { + internal static Task CompletedTask #if netstandard - /// <summary>A successfully completed task.</summary> - private static readonly Task s_completedTask = Task.Delay(0); + { get; } = Task.Delay(0); +#else + => Task.CompletedTask; #endif /// <summary>null if representing a successful synchronous completion, otherwise a <see cref="Task"/> or a <see cref="IValueTaskSource"/>.</summary> @@ -149,12 +151,7 @@ namespace System.Threading.Tasks /// manufacture a new task object to represent the result. /// </remarks> public Task AsTask() => - _obj == null ? -#if netstandard - s_completedTask : -#else - Task.CompletedTask : -#endif + _obj == null ? ValueTask.CompletedTask : ObjectIsTask ? UnsafeTask : GetTaskForValueTaskSource(); @@ -173,12 +170,7 @@ namespace System.Threading.Tasks // Propagate any exceptions that may have occurred, then return // an already successfully completed task. t.GetResult(_token); - return -#if netstandard - s_completedTask; -#else - Task.CompletedTask; -#endif + return ValueTask.CompletedTask; // If status is Faulted or Canceled, GetResult should throw. But // we can't guarantee every implementation will do the "right thing". |