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

Use AsyncTaskCache in ValueTask.AsTask() #13907

Merged
merged 1 commit into from
Sep 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/mscorlib/shared/System/Threading/Tasks/ValueTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public Task<TResult> AsTask() =>
// Return the task if we were constructed from one, otherwise manufacture one. We don't
// cache the generated task into _task as it would end up changing both equality comparison
// and the hash code we generate in GetHashCode.
_task ?? Task.FromResult(_result);
_task ?? AsyncTaskMethodBuilder<TResult>.GetTaskForResult(_result);

/// <summary>Gets whether the <see cref="ValueTask{TResult}"/> represents a completed operation.</summary>
public bool IsCompleted => _task == null || _task.IsCompleted;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ internal void SetNotificationForWaitCompletion(bool enabled)
/// <param name="result">The result for which we need a task.</param>
/// <returns>The completed task containing the result.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)] // method looks long, but for a given TResult it results in a relatively small amount of asm
private Task<TResult> GetTaskForResult(TResult result)
internal static Task<TResult> GetTaskForResult(TResult result)
{
Contract.Ensures(
EqualityComparer<TResult>.Default.Equals(result, Contract.Result<Task<TResult>>().Result),
Expand Down