Skip to content
Closed
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
21 changes: 18 additions & 3 deletions sdk/core/Azure.Core/src/Shared/TaskExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,16 @@ public static T EnsureCompleted<T>(this ValueTask<T> task)
#if DEBUG
VerifyTaskCompleted(task.IsCompleted);
#endif

#pragma warning disable AZC0102 // Do not use GetAwaiter().GetResult(). Use the TaskExtensions.EnsureCompleted() extension method instead.
return task.GetAwaiter().GetResult();
if (task.IsCompleted)
{
return task.GetAwaiter().GetResult();
}
else
{
return task.AsTask().GetAwaiter().GetResult();
}
#pragma warning restore AZC0102 // Do not use GetAwaiter().GetResult(). Use the TaskExtensions.EnsureCompleted() extension method instead.
}

Expand All @@ -49,8 +57,16 @@ public static void EnsureCompleted(this ValueTask task)
#if DEBUG
VerifyTaskCompleted(task.IsCompleted);
#endif

#pragma warning disable AZC0102 // Do not use GetAwaiter().GetResult(). Use the TaskExtensions.EnsureCompleted() extension method instead.
task.GetAwaiter().GetResult();
if (task.IsCompleted)
{
task.GetAwaiter().GetResult();
}
else
{
task.AsTask().GetAwaiter().GetResult();
}
#pragma warning restore AZC0102 // Do not use GetAwaiter().GetResult(). Use the TaskExtensions.EnsureCompleted() extension method instead.
}

Expand All @@ -69,7 +85,6 @@ public static ConfiguredValueTaskAwaitable<T> EnsureCompleted<T>(this Configured

public static ConfiguredValueTaskAwaitable EnsureCompleted(this ConfiguredValueTaskAwaitable awaitable, bool async)
{

if (!async)
{
#if DEBUG
Expand Down