#if NET20 || NET30 || NET35 || NET40 || !NET_4_6
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Runtime.InteropServices;
using System.Threading.Tasks;
namespace System.Runtime.CompilerServices
{
/// Provides an awaiter for a .
public struct ValueTaskAwaiter : ICriticalNotifyCompletion
{
/// The value being awaited.
private readonly ValueTask _value;
/// Initializes the awaiter.
/// The value to be awaited.
internal ValueTaskAwaiter(ValueTask value) { _value = value; }
/// Gets whether the has completed.
public bool IsCompleted { get { return _value.IsCompleted; } }
/// Gets the result of the ValueTask.
public TResult GetResult()
{
return _value._task == null ?
_value._result :
_value._task.GetAwaiter().GetResult();
}
/// Schedules the continuation action for this ValueTask.
public void OnCompleted(Action continuation)
{
_value.AsTask().ConfigureAwait(continueOnCapturedContext: true).GetAwaiter().OnCompleted(continuation);
}
/// Schedules the continuation action for this ValueTask.
public void UnsafeOnCompleted(Action continuation)
{
_value.AsTask().ConfigureAwait(continueOnCapturedContext: true).GetAwaiter().UnsafeOnCompleted(continuation);
}
}
}
#endif