// 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;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
namespace CommunityToolkit.Mvvm.ComponentModel.__Internals;
///
/// An internal helper used to support and generated code from its template.
/// This type is not intended to be used directly by user code.
///
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This type is not intended to be used directly by user code")]
public static class __TaskExtensions
{
///
/// Gets an awaitable object that skips end validation.
///
/// The input to get the awaitable for.
/// A object wrapping .
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This method is not intended to be called directly by user code")]
public static TaskAwaitableWithoutEndValidation GetAwaitableWithoutEndValidation(this Task task)
{
return new(task);
}
///
/// A custom task awaitable object that skips end validation.
///
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("This type is not intended to be called directly by user code")]
public readonly struct TaskAwaitableWithoutEndValidation
{
///
/// The wrapped instance to create an awaiter for.
///
private readonly Task task;
///
/// Creates a new instance with the specified parameters.
///
/// The wrapped instance to create an awaiter for.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public TaskAwaitableWithoutEndValidation(Task task)
{
this.task = task;
}
///
/// Gets an instance for the current underlying task.
///
/// An instance for the current underlying task.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Awaiter GetAwaiter()
{
return new(this.task);
}
///
/// An awaiter object for .
///
public readonly struct Awaiter : ICriticalNotifyCompletion
{
///
/// The underlying instance.
///
private readonly TaskAwaiter taskAwaiter;
///
/// Creates a new instance with the specified parameters.
///
/// The wrapped instance to create an awaiter for.
public Awaiter(Task task)
{
this.taskAwaiter = task.GetAwaiter();
}
///
/// Gets whether the operation has completed or not.
///
/// This property is intended for compiler user rather than use directly in code.
public bool IsCompleted
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => this.taskAwaiter.IsCompleted;
}
///
/// Ends the await operation.
///
/// This method is intended for compiler user rather than use directly in code.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void GetResult()
{
}
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void OnCompleted(Action continuation)
{
this.taskAwaiter.OnCompleted(continuation);
}
///
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void UnsafeOnCompleted(Action continuation)
{
this.taskAwaiter.UnsafeOnCompleted(continuation);
}
}
}
}