From b2576934989b831ac8084fa382906dca8c4ca22f Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Tue, 26 Sep 2017 22:39:38 -0400 Subject: [PATCH] Merge pull request dotnet/coreclr#14178 from stephentoub/async_avoid_delegate Avoid async method delegate allocation Signed-off-by: dotnet-bot --- .../Runtime/CompilerServices/ConfiguredValueTaskAwaitable.cs | 5 ++++- .../System/Runtime/CompilerServices/ValueTaskAwaiter.cs | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConfiguredValueTaskAwaitable.cs b/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConfiguredValueTaskAwaitable.cs index 4ec931c4af3..0784e6135c8 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConfiguredValueTaskAwaitable.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConfiguredValueTaskAwaitable.cs @@ -39,7 +39,7 @@ public struct ConfiguredValueTaskAwaiter : ICriticalNotifyCompletion /// The value being awaited. private ValueTask _value; // Methods are called on this; avoid making it readonly so as to avoid unnecessary copies /// The value to pass to ConfigureAwait. - private readonly bool _continueOnCapturedContext; + internal readonly bool _continueOnCapturedContext; /// Initializes the awaiter. /// The value to be awaited. @@ -66,6 +66,9 @@ public void OnCompleted(Action continuation) => /// Schedules the continuation action for the . public void UnsafeOnCompleted(Action continuation) => _value.AsTask().ConfigureAwait(_continueOnCapturedContext).GetAwaiter().UnsafeOnCompleted(continuation); + + /// Gets the task underlying . + internal Task AsTask() => _value.AsTask(); } } } diff --git a/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ValueTaskAwaiter.cs b/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ValueTaskAwaiter.cs index c4194825217..30e688e0771 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ValueTaskAwaiter.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ValueTaskAwaiter.cs @@ -33,5 +33,8 @@ public void OnCompleted(Action continuation) => /// Schedules the continuation action for this ValueTask. public void UnsafeOnCompleted(Action continuation) => _value.AsTask().ConfigureAwait(continueOnCapturedContext: true).GetAwaiter().UnsafeOnCompleted(continuation); + + /// Gets the task underlying . + internal Task AsTask() => _value.AsTask(); } }