Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit cbd3f54

Browse files
committed
Expose Task.IsCompletedSuccessfully
1 parent bbe202b commit cbd3f54

File tree

6 files changed

+10
-11
lines changed

6 files changed

+10
-11
lines changed

src/mscorlib/shared/System/Threading/Tasks/TaskExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static Task Unwrap(this Task<Task> task)
2121
// it completed successfully. Return its inner task to avoid unnecessary wrapping, or if the inner
2222
// task is null, return a canceled task to match the same semantics as CreateUnwrapPromise.
2323
return
24-
!task.IsRanToCompletion ? Task.CreateUnwrapPromise<VoidTaskResult>(task, lookForOce: false) :
24+
!task.IsCompletedSuccessfully ? Task.CreateUnwrapPromise<VoidTaskResult>(task, lookForOce: false) :
2525
task.Result ??
2626
Task.FromCanceled(new CancellationToken(true));
2727
}
@@ -40,7 +40,7 @@ public static Task<TResult> Unwrap<TResult>(this Task<Task<TResult>> task)
4040
// it completed successfully. Return its inner task to avoid unnecessary wrapping, or if the inner
4141
// task is null, return a canceled task to match the same semantics as CreateUnwrapPromise.
4242
return
43-
!task.IsRanToCompletion ? Task.CreateUnwrapPromise<TResult>(task, lookForOce: false) :
43+
!task.IsCompletedSuccessfully ? Task.CreateUnwrapPromise<TResult>(task, lookForOce: false) :
4444
task.Result ??
4545
Task.FromCanceled<TResult>(new CancellationToken(true));
4646
}

src/mscorlib/src/System/IO/Stream.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,14 +522,14 @@ private void RunReadWriteTaskWhenReady(Task asyncWaiter, ReadWriteTask readWrite
522522
// If the wait has already completed, run the task.
523523
if (asyncWaiter.IsCompleted)
524524
{
525-
Debug.Assert(asyncWaiter.IsRanToCompletion, "The semaphore wait should always complete successfully.");
525+
Debug.Assert(asyncWaiter.IsCompletedSuccessfully, "The semaphore wait should always complete successfully.");
526526
RunReadWriteTask(readWriteTask);
527527
}
528528
else // Otherwise, wait for our turn, and then run the task.
529529
{
530530
asyncWaiter.ContinueWith((t, state) =>
531531
{
532-
Debug.Assert(t.IsRanToCompletion, "The semaphore wait should always complete successfully.");
532+
Debug.Assert(t.IsCompletedSuccessfully, "The semaphore wait should always complete successfully.");
533533
var rwt = (ReadWriteTask)state;
534534
rwt._stream.RunReadWriteTask(rwt); // RunReadWriteTask(readWriteTask);
535535
}, readWriteTask, default(CancellationToken), TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);

src/mscorlib/src/System/Runtime/CompilerServices/TaskAwaiter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ private static void HandleNonSuccessAndDebuggerNotification(Task task)
146146
task.NotifyDebuggerOfWaitCompletionIfNecessary();
147147

148148
// And throw an exception if the task is faulted or canceled.
149-
if (!task.IsRanToCompletion) ThrowForNonSuccess(task);
149+
if (!task.IsCompletedSuccessfully) ThrowForNonSuccess(task);
150150
}
151151

152152
/// <summary>Throws an exception to handle a task that completed in a state other than RanToCompletion.</summary>

src/mscorlib/src/System/Threading/Tasks/Task.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,8 +1467,7 @@ private static bool IsCompletedMethod(int flags)
14671467
return (flags & TASK_STATE_COMPLETED_MASK) != 0;
14681468
}
14691469

1470-
// For use in InternalWait -- marginally faster than (Task.Status == TaskStatus.RanToCompletion)
1471-
internal bool IsRanToCompletion
1470+
public bool IsCompletedSuccessfully
14721471
{
14731472
get { return (m_stateFlags & TASK_STATE_COMPLETED_MASK) == TASK_STATE_RAN_TO_COMPLETION; }
14741473
}

src/mscorlib/src/System/Threading/Tasks/TaskContinuation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ internal override void Run(Task completedTask, bool bCanInlineContinuationTask)
320320
// activation criteria of the TaskContinuationOptions.
321321
TaskContinuationOptions options = m_options;
322322
bool isRightKind =
323-
completedTask.IsRanToCompletion ?
323+
completedTask.IsCompletedSuccessfully ?
324324
(options & TaskContinuationOptions.NotOnRanToCompletion) == 0 :
325325
(completedTask.IsCanceled ?
326326
(options & TaskContinuationOptions.NotOnCanceled) == 0 :

src/mscorlib/src/System/Threading/Tasks/future.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ private string DebuggerDisplayResultDescription
374374
{
375375
get
376376
{
377-
return IsRanToCompletion ? "" + m_result : SR.TaskT_DebuggerNoResult;
377+
return IsCompletedSuccessfully ? "" + m_result : SR.TaskT_DebuggerNoResult;
378378
}
379379
}
380380

@@ -491,10 +491,10 @@ internal TResult GetResultCore(bool waitCompletionNotification)
491491
if (waitCompletionNotification) NotifyDebuggerOfWaitCompletionIfNecessary();
492492

493493
// Throw an exception if appropriate.
494-
if (!IsRanToCompletion) ThrowIfExceptional(includeTaskCanceledExceptions: true);
494+
if (!IsCompletedSuccessfully) ThrowIfExceptional(includeTaskCanceledExceptions: true);
495495

496496
// We shouldn't be here if the result has not been set.
497-
Debug.Assert(IsRanToCompletion, "Task<T>.Result getter: Expected result to have been set.");
497+
Debug.Assert(IsCompletedSuccessfully, "Task<T>.Result getter: Expected result to have been set.");
498498

499499
return m_result;
500500
}

0 commit comments

Comments
 (0)