Beispiel #1
0
        public static CoroutineAwaiter GetAwaiter(this YieldInstruction instruction)
        {
            CoroutineAwaiter awaiter = new CoroutineAwaiter();

            RunOnCoroutine(DoYieldInstruction(instruction), e => awaiter.SetResult(e));
            return(awaiter);
        }
Beispiel #2
0
        public static CoroutineAwaiter <CustomYieldInstruction> GetAwaiter(this CustomYieldInstruction target)
        {
            CoroutineAwaiter <CustomYieldInstruction> awaiter = new CoroutineAwaiter <CustomYieldInstruction>();

            RunOnCoroutine(DoYieldInstruction(target), e => awaiter.SetResult(target, e));
            return(awaiter);
        }
Beispiel #3
0
        public static CoroutineAwaiter GetAwaiter(this IEnumerator coroutine)
        {
            CoroutineAwaiter awaiter = new CoroutineAwaiter();

            RunOnCoroutine(coroutine, e => awaiter.SetResult(e));
            return(awaiter);
        }
Beispiel #4
0
        public static CoroutineAwaiter <AssetBundle> GetAwaiter(this AssetBundleCreateRequest target)
        {
            CoroutineAwaiter <AssetBundle> awaiter = new CoroutineAwaiter <AssetBundle>();

            RunOnCoroutine(DoYieldInstruction(target), e => awaiter.SetResult(target.assetBundle, e));
            return(awaiter);
        }
Beispiel #5
0
        public static CoroutineAwaiter <UnityEngine.Object> GetAwaiter(this ResourceRequest target)
        {
            CoroutineAwaiter <UnityEngine.Object> awaiter = new CoroutineAwaiter <UnityEngine.Object>();

            RunOnCoroutine(DoYieldInstruction(target), e => awaiter.SetResult(target.asset, e));
            return(awaiter);
        }
Beispiel #6
0
        public static CoroutineAwaiter <UnityWebRequestAsyncOperation> GetAwaiter(this UnityWebRequestAsyncOperation target)
        {
            CoroutineAwaiter <UnityWebRequestAsyncOperation> awaiter = new CoroutineAwaiter <UnityWebRequestAsyncOperation>();

            RunOnCoroutine(DoYieldInstruction(target), e => awaiter.SetResult(target, e));
            return(awaiter);
        }
        public static IAwaiter GetAwaiter(this WaitForMainThread instruction)
        {
            CoroutineAwaiter awaiter = new CoroutineAwaiter();

            Executors.RunOnMainThread(() =>
            {
                awaiter.SetResult(null);
            });
            return(awaiter);
        }
        public static IAwaiter GetAwaiter(this WaitForBackgroundThread instruction)
        {
            CoroutineAwaiter awaiter = new CoroutineAwaiter();

            Executors.RunAsyncNoReturn(() =>
            {
                awaiter.SetResult(null);
            });
            return(awaiter);
        }
        public virtual CoroutineAwaiter GetAwaiter()
        {
            CoroutineAwaiter awaiter = new CoroutineAwaiter();

            this.asyncResult.Callbackable().OnCallback(ar =>
            {
                awaiter.SetResult(ar.Exception);
            });
            return(awaiter);
        }
Beispiel #10
0
        public static CoroutineAwaiter <TResult> GetAwaiter <TResult>(this IAsyncResult <TResult> asyncResult)
        {
            CoroutineAwaiter <TResult> awaiter = new CoroutineAwaiter <TResult>();

            asyncResult.Callbackable().OnCallback(ar =>
            {
                awaiter.SetResult(ar.Result, ar.Exception);
            });
            return(awaiter);
        }
        private static CoroutineAwaiter <TResult> RunOnCoroutine <TResult>(IEnumerator routine, Func <TResult> getter)
        {
            CoroutineAwaiter <TResult> awaiter    = new CoroutineAwaiter <TResult>();
            InterceptableEnumerator    enumerator = routine is InterceptableEnumerator ? (InterceptableEnumerator)routine : new InterceptableEnumerator(routine);

            enumerator.RegisterCatchBlock(e =>
            {
                awaiter.SetResult(default(TResult), e);
            });
            enumerator.RegisterFinallyBlock(() =>
            {
                if (!awaiter.IsCompleted)
                {
                    awaiter.SetResult(getter(), null);
                }
            });
            Executors.RunOnCoroutineNoReturn(enumerator);
            return(awaiter);
        }
        private static CoroutineAwaiter RunOnCoroutine(IEnumerator routine)
        {
            CoroutineAwaiter        awaiter    = new CoroutineAwaiter();
            InterceptableEnumerator enumerator = routine is InterceptableEnumerator ? (InterceptableEnumerator)routine : new InterceptableEnumerator(routine);

            enumerator.RegisterCatchBlock(e =>
            {
                awaiter.SetResult(e);
            });
            enumerator.RegisterFinallyBlock(() =>
            {
                if (!awaiter.IsCompleted)
                {
                    awaiter.SetResult(null);
                }
            });
            Executors.RunOnCoroutineNoReturn(enumerator);
            return(awaiter);
        }