From eadfbd529bf1db1cbd854572b745bca8bf25b9d8 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Thu, 1 Mar 2018 08:59:32 -0500 Subject: [PATCH] Adjust System.Threading.Tasks.Extensions for IValueTaskSource Signed-off-by: dotnet-bot-corefx-mirror --- .../CompilerServices/ConfiguredValueTaskAwaitable.cs | 8 ++++---- .../Runtime/CompilerServices/ValueTaskAwaiter.cs | 8 ++++---- .../Threading/Tasks/Sources/IValueTaskSource.cs | 3 +-- .../shared/System/Threading/Tasks/ValueTask.cs | 20 ++++++-------------- 4 files changed, 15 insertions(+), 24 deletions(-) diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/ConfiguredValueTaskAwaitable.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/ConfiguredValueTaskAwaitable.cs index 65d3d56..e85e42e 100644 --- a/src/mscorlib/shared/System/Runtime/CompilerServices/ConfiguredValueTaskAwaitable.cs +++ b/src/mscorlib/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/mscorlib/shared/System/Runtime/CompilerServices/ValueTaskAwaiter.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/ValueTaskAwaiter.cs index 0414a05..2dad5d5 100644 --- a/src/mscorlib/shared/System/Runtime/CompilerServices/ValueTaskAwaiter.cs +++ b/src/mscorlib/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/mscorlib/shared/System/Threading/Tasks/Sources/IValueTaskSource.cs b/src/mscorlib/shared/System/Threading/Tasks/Sources/IValueTaskSource.cs index 3c1e883..e411146 100644 --- a/src/mscorlib/shared/System/Threading/Tasks/Sources/IValueTaskSource.cs +++ b/src/mscorlib/shared/System/Threading/Tasks/Sources/IValueTaskSource.cs @@ -23,8 +23,7 @@ namespace System.Threading.Tasks.Sources /// UseSchedulingContext = 0x1, /// - /// Set if OnCompleted should capture the current and use it to - /// the continuation. + /// Set if OnCompleted should capture the current ExecutionContext and use it to run the continuation. /// FlowExecutionContext = 0x2, } diff --git a/src/mscorlib/shared/System/Threading/Tasks/ValueTask.cs b/src/mscorlib/shared/System/Threading/Tasks/ValueTask.cs index 6c45ed6..c46a6cb 100644 --- a/src/mscorlib/shared/System/Threading/Tasks/ValueTask.cs +++ b/src/mscorlib/shared/System/Threading/Tasks/ValueTask.cs @@ -25,9 +25,11 @@ namespace System.Threading.Tasks [StructLayout(LayoutKind.Auto)] public readonly struct ValueTask : IEquatable { + internal static Task CompletedTask #if netstandard - /// A successfully completed task. - private static readonly Task s_completedTask = Task.Delay(0); + { get; } = Task.Delay(0); +#else + => Task.CompletedTask; #endif /// null if representing a successful synchronous completion, otherwise a or a . @@ -149,12 +151,7 @@ namespace System.Threading.Tasks /// manufacture a new task object to represent the result. /// 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". -- 2.7.4