Adjust System.Threading.Tasks.Extensions for IValueTaskSource
authorStephen Toub <stoub@microsoft.com>
Thu, 1 Mar 2018 13:59:32 +0000 (08:59 -0500)
committerStephen Toub <stoub@microsoft.com>
Thu, 1 Mar 2018 16:09:00 +0000 (11:09 -0500)
Signed-off-by: dotnet-bot-corefx-mirror <dotnet-bot@microsoft.com>
src/mscorlib/shared/System/Runtime/CompilerServices/ConfiguredValueTaskAwaitable.cs
src/mscorlib/shared/System/Runtime/CompilerServices/ValueTaskAwaiter.cs
src/mscorlib/shared/System/Threading/Tasks/Sources/IValueTaskSource.cs
src/mscorlib/shared/System/Threading/Tasks/ValueTask.cs

index 65d3d56..e85e42e 100644 (file)
@@ -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);
                 }
             }
 
index 0414a05..2dad5d5 100644 (file)
@@ -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);
             }
         }
 
index 3c1e883..e411146 100644 (file)
@@ -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,
     }
index 6c45ed6..c46a6cb 100644 (file)
@@ -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".