using System;
using System.Threading.Tasks;
namespace Unity.Services.Core
{
///
/// Set of utility functions added as extensions to
/// and .
///
static class AsyncOperationExtensions
{
///
/// Get a default awaiter on .
///
///
/// The operation to create an awaiter for.
///
///
/// Return a default awaiter for .
///
///
/// This is required so we can directly use the
/// keyword on an .
///
public static AsyncOperationAwaiter GetAwaiter(this IAsyncOperation self)
{
return new AsyncOperationAwaiter(self);
}
///
/// Get a Task based on .
///
///
/// The operation to create a Task for.
///
///
/// Return a .
///
public static Task AsTask(this IAsyncOperation self)
{
if (self.Status == AsyncOperationStatus.Succeeded)
{
return Task.CompletedTask;
}
var taskCompletionSource = new TaskCompletionSource