<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.0-preview2-26406-04" />

ValueTaskAwaiter<TResult>

using System.Diagnostics; using System.Threading.Tasks; using System.Threading.Tasks.Sources; namespace System.Runtime.CompilerServices { public readonly struct ValueTaskAwaiter<TResult> : ICriticalNotifyCompletion, INotifyCompletion { private readonly ValueTask<TResult> _value; public bool IsCompleted { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return _value.IsCompleted; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal ValueTaskAwaiter(ValueTask<TResult> value) { _value = value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Diagnostics.StackTraceHidden] public TResult GetResult() { return _value.Result; } public void OnCompleted(Action continuation) { if (_value.ObjectIsTask) _value.UnsafeGetTask().GetAwaiter().OnCompleted(continuation); else if (_value._obj != null) { _value.UnsafeGetValueTaskSource().OnCompleted(ValueTaskAwaiter.s_invokeActionDelegate, continuation, _value._token, ValueTaskSourceOnCompletedFlags.UseSchedulingContext | ValueTaskSourceOnCompletedFlags.FlowExecutionContext); } else { ValueTask.CompletedTask.GetAwaiter().OnCompleted(continuation); } } public void UnsafeOnCompleted(Action continuation) { if (_value.ObjectIsTask) _value.UnsafeGetTask().GetAwaiter().UnsafeOnCompleted(continuation); else if (_value._obj != null) { _value.UnsafeGetValueTaskSource().OnCompleted(ValueTaskAwaiter.s_invokeActionDelegate, continuation, _value._token, ValueTaskSourceOnCompletedFlags.UseSchedulingContext); } else { ValueTask.CompletedTask.GetAwaiter().UnsafeOnCompleted(continuation); } } } }