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

Commit

Permalink
Share completed Task between Task and AsyncTaskMethodBuilder (#27437)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub authored and jkotas committed Oct 25, 2019
1 parent 8ef3510 commit ed525ba
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ namespace System.Runtime.CompilerServices
/// </remarks>
public struct AsyncTaskMethodBuilder
{
/// <summary>A cached VoidTaskResult task used for builders that complete synchronously.</summary>
private static readonly Task<VoidTaskResult> s_cachedCompleted = AsyncTaskMethodBuilder<VoidTaskResult>.s_defaultResultTask;

/// <summary>The lazily-initialized built task.</summary>
private Task<VoidTaskResult>? m_task; // Debugger depends on the exact name of this field.

Expand Down Expand Up @@ -103,7 +100,7 @@ public void SetResult()
// If there isn't one, store the supplied completed task.
if (m_task is null)
{
m_task = s_cachedCompleted;
m_task = Task.s_cachedCompleted;
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1434,8 +1434,12 @@ WaitHandle IAsyncResult.AsyncWaitHandle
/// </remarks>
public static TaskFactory Factory { get; } = new TaskFactory();

/// <summary>Singleton cached task that's been completed successfully.</summary>
/// <remarks>It's a <see cref="Task{VoidTaskResult}"/> so it can be shared with <see cref="AsyncTaskMethodBuilder"/>.</remarks>
internal static readonly Task<VoidTaskResult> s_cachedCompleted = new Task<VoidTaskResult>(false, default, (TaskCreationOptions)InternalTaskOptions.DoNotDispose, default);

/// <summary>Gets a task that's already been completed successfully.</summary>
public static Task CompletedTask { get; } = new Task(false, (TaskCreationOptions)InternalTaskOptions.DoNotDispose, default);
public static Task CompletedTask => s_cachedCompleted;

/// <summary>
/// Provides an event that can be used to wait for completion.
Expand Down

0 comments on commit ed525ba

Please sign in to comment.