Expose Task.IsCompletedSuccessfully
authorStephen Toub <stoub@microsoft.com>
Tue, 18 Apr 2017 17:57:19 +0000 (13:57 -0400)
committerStephen Toub <stoub@microsoft.com>
Tue, 18 Apr 2017 17:57:19 +0000 (13:57 -0400)
Commit migrated from https://github.com/dotnet/coreclr/commit/cbd3f54c7dbd3808e2d8b1e4dc1040f511147d19

src/coreclr/src/mscorlib/shared/System/Threading/Tasks/TaskExtensions.cs
src/coreclr/src/mscorlib/src/System/IO/Stream.cs
src/coreclr/src/mscorlib/src/System/Runtime/CompilerServices/TaskAwaiter.cs
src/coreclr/src/mscorlib/src/System/Threading/Tasks/Task.cs
src/coreclr/src/mscorlib/src/System/Threading/Tasks/TaskContinuation.cs
src/coreclr/src/mscorlib/src/System/Threading/Tasks/future.cs

index 1098299..97f2013 100644 (file)
@@ -21,7 +21,7 @@ namespace System.Threading.Tasks
             // it completed successfully.  Return its inner task to avoid unnecessary wrapping, or if the inner
             // task is null, return a canceled task to match the same semantics as CreateUnwrapPromise.
             return
-                !task.IsRanToCompletion ? Task.CreateUnwrapPromise<VoidTaskResult>(task, lookForOce: false) :
+                !task.IsCompletedSuccessfully ? Task.CreateUnwrapPromise<VoidTaskResult>(task, lookForOce: false) :
                 task.Result ??
                 Task.FromCanceled(new CancellationToken(true));
         }
@@ -40,7 +40,7 @@ namespace System.Threading.Tasks
             // it completed successfully.  Return its inner task to avoid unnecessary wrapping, or if the inner
             // task is null, return a canceled task to match the same semantics as CreateUnwrapPromise.
             return
-                !task.IsRanToCompletion ? Task.CreateUnwrapPromise<TResult>(task, lookForOce: false) :
+                !task.IsCompletedSuccessfully ? Task.CreateUnwrapPromise<TResult>(task, lookForOce: false) :
                 task.Result ??
                 Task.FromCanceled<TResult>(new CancellationToken(true));
         }
index 92fe374..65cc4dd 100644 (file)
@@ -522,14 +522,14 @@ namespace System.IO
             // If the wait has already completed, run the task.
             if (asyncWaiter.IsCompleted)
             {
-                Debug.Assert(asyncWaiter.IsRanToCompletion, "The semaphore wait should always complete successfully.");
+                Debug.Assert(asyncWaiter.IsCompletedSuccessfully, "The semaphore wait should always complete successfully.");
                 RunReadWriteTask(readWriteTask);
             }
             else  // Otherwise, wait for our turn, and then run the task.
             {
                 asyncWaiter.ContinueWith((t, state) =>
                 {
-                    Debug.Assert(t.IsRanToCompletion, "The semaphore wait should always complete successfully.");
+                    Debug.Assert(t.IsCompletedSuccessfully, "The semaphore wait should always complete successfully.");
                     var rwt = (ReadWriteTask)state;
                     rwt._stream.RunReadWriteTask(rwt); // RunReadWriteTask(readWriteTask);
                 }, readWriteTask, default(CancellationToken), TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
index e2fa6ca..c35658e 100644 (file)
@@ -146,7 +146,7 @@ namespace System.Runtime.CompilerServices
             task.NotifyDebuggerOfWaitCompletionIfNecessary();
 
             // And throw an exception if the task is faulted or canceled.
-            if (!task.IsRanToCompletion) ThrowForNonSuccess(task);
+            if (!task.IsCompletedSuccessfully) ThrowForNonSuccess(task);
         }
 
         /// <summary>Throws an exception to handle a task that completed in a state other than RanToCompletion.</summary>
index 8e2e6a4..0a9248c 100644 (file)
@@ -1467,8 +1467,7 @@ namespace System.Threading.Tasks
             return (flags & TASK_STATE_COMPLETED_MASK) != 0;
         }
 
-        // For use in InternalWait -- marginally faster than (Task.Status == TaskStatus.RanToCompletion)
-        internal bool IsRanToCompletion
+        public bool IsCompletedSuccessfully
         {
             get { return (m_stateFlags & TASK_STATE_COMPLETED_MASK) == TASK_STATE_RAN_TO_COMPLETION; }
         }
index 848a0ec..de22235 100644 (file)
@@ -320,7 +320,7 @@ namespace System.Threading.Tasks
             // activation criteria of the TaskContinuationOptions.
             TaskContinuationOptions options = m_options;
             bool isRightKind =
-                completedTask.IsRanToCompletion ?
+                completedTask.IsCompletedSuccessfully ?
                     (options & TaskContinuationOptions.NotOnRanToCompletion) == 0 :
                     (completedTask.IsCanceled ?
                         (options & TaskContinuationOptions.NotOnCanceled) == 0 :
index 26c2388..bf9000e 100644 (file)
@@ -374,7 +374,7 @@ namespace System.Threading.Tasks
         {
             get
             {
-                return IsRanToCompletion ? "" + m_result : SR.TaskT_DebuggerNoResult;
+                return IsCompletedSuccessfully ? "" + m_result : SR.TaskT_DebuggerNoResult;
             }
         }
 
@@ -491,10 +491,10 @@ namespace System.Threading.Tasks
             if (waitCompletionNotification) NotifyDebuggerOfWaitCompletionIfNecessary();
 
             // Throw an exception if appropriate.
-            if (!IsRanToCompletion) ThrowIfExceptional(includeTaskCanceledExceptions: true);
+            if (!IsCompletedSuccessfully) ThrowIfExceptional(includeTaskCanceledExceptions: true);
 
             // We shouldn't be here if the result has not been set.
-            Debug.Assert(IsRanToCompletion, "Task<T>.Result getter: Expected result to have been set.");
+            Debug.Assert(IsCompletedSuccessfully, "Task<T>.Result getter: Expected result to have been set.");
 
             return m_result;
         }