// Copyright (c) Alexander Bogarsukov. // Licensed under the MIT license. See the LICENSE.md file in the project root for more information. using System; using UnityEngine; using UnityEngine.Networking; namespace UnityFx.Tasks { /// /// Async/await extensions. /// public static class AwaitExtensions { /// /// Returns the awaiter. This method is intended for compiler use only. /// /// The operation to await. /// Returns the operation awaiter. public static CompilerServices.AsyncOperationAwaiter GetAwaiter(this AsyncOperation op) { return new CompilerServices.AsyncOperationAwaiter(op); } /// /// Returns the awaiter. This method is intended for compiler use only. /// /// The operation to await. /// Returns the operation awaiter. public static CompilerServices.YieldInstructionAwaiter GetAwaiter(this YieldInstruction op) { return new CompilerServices.YieldInstructionAwaiter(op); } /// /// Returns the awaiter. This method is intended for compiler use only. /// /// The operation to await. /// Returns the operation awaiter. public static CompilerServices.ResourceRequestAwaiter GetAwaiter(this ResourceRequest op) { return new CompilerServices.ResourceRequestAwaiter(op); } /// /// Creates a configurable awaitable object for the instance. /// /// Type of the operation result value. /// The source operation. /// Returns an awaitable object that can track the operation completion. public static CompilerServices.ResourceRequestAwaitable ConfigureAwait(this ResourceRequest op) where T : UnityEngine.Object { return new CompilerServices.ResourceRequestAwaitable(op); } /// /// Returns the awaiter. This method is intended for compiler use only. /// /// The operation to await. /// Returns the operation awaiter. public static CompilerServices.AssetBundleRequestAwaiter GetAwaiter(this AssetBundleRequest op) { return new CompilerServices.AssetBundleRequestAwaiter(op); } /// /// Creates a configurable awaitable object for the instance. /// /// Type of the operation result value. /// The source operation. /// Returns an awaitable object that can track the operation completion. public static CompilerServices.AssetBundleRequestAwaitable ConfigureAwait(this AssetBundleRequest op) where T : UnityEngine.Object { return new CompilerServices.AssetBundleRequestAwaitable(op); } /// /// Returns the awaiter. This method is intended for compiler use only. /// /// The operation to await. /// Returns the operation awaiter. public static CompilerServices.AssetBundleCreateRequestAwaiter GetAwaiter(this AssetBundleCreateRequest op) { return new CompilerServices.AssetBundleCreateRequestAwaiter(op); } /// /// Returns the awaiter. This method is intended for compiler use only. /// /// The operation to await. /// Returns the operation awaiter. public static CompilerServices.UnityWebRequestAwaiter GetAwaiter(this UnityWebRequest op) { return new CompilerServices.UnityWebRequestAwaiter(op); } /// /// Creates a configurable awaitable object for the instance. /// /// Type of the request result value. /// The source web request. /// Returns an awaitable object that can track the request completion. public static CompilerServices.UnityWebRequestAwaitable ConfigureAwait(this UnityWebRequest request) where T : class { return new CompilerServices.UnityWebRequestAwaitable(request); } /// /// Creates a configurable awaitable object for the instance. /// /// Type of the operation result value. /// The source operation. /// Returns an awaitable object that can track the operation completion. public static CompilerServices.UnityWebRequestAwaitable ConfigureAwait(this UnityWebRequestAsyncOperation op) where T : class { return new CompilerServices.UnityWebRequestAwaitable(op.webRequest); } } }