using System; namespace Unity.Services.Core.Internal { /// /// Default implementation for . /// struct AsyncOperationAwaiter : IAsyncOperationAwaiter { IAsyncOperation m_Operation; /// /// Create an awaiter for the given . /// /// /// The operation to await. /// public AsyncOperationAwaiter(IAsyncOperation asyncOperation) { m_Operation = asyncOperation; } /// /// Schedules the continuation action that's invoked when the instance completes. /// /// /// The action to invoke when the operation completes. /// /// /// Straightforward implementation of . /// public void OnCompleted(Action continuation) { m_Operation.Completed += operation => continuation(); } /// public void UnsafeOnCompleted(Action continuation) { m_Operation.Completed += operation => continuation(); } /// public bool IsCompleted => m_Operation.IsDone; /// public void GetResult() { if (m_Operation.Status == AsyncOperationStatus.Failed || m_Operation.Status == AsyncOperationStatus.Cancelled) { throw m_Operation.Exception; } } } /// /// Default implementation for . /// /// /// The result's type of the awaited operation. /// struct AsyncOperationAwaiter : IAsyncOperationAwaiter { IAsyncOperation m_Operation; /// /// Create an awaiter for the given . /// /// /// The operation to await. /// public AsyncOperationAwaiter(IAsyncOperation asyncOperation) { m_Operation = asyncOperation; } /// public void OnCompleted(Action continuation) { m_Operation.Completed += obj => continuation(); } /// public void UnsafeOnCompleted(Action continuation) { m_Operation.Completed += obj => continuation(); } /// public bool IsCompleted => m_Operation.IsDone; /// public T GetResult() { if (m_Operation.Status == AsyncOperationStatus.Failed || m_Operation.Status == AsyncOperationStatus.Cancelled) { throw m_Operation.Exception; } return m_Operation.Result; } } }