コード例 #1
0
        public static IAwaiter GetAwaiter(this WaitForMainThread instruction)
        {
            CoroutineAwaiter awaiter = new CoroutineAwaiter();

            Executors.RunOnMainThread(() => { awaiter.SetResult(null); });
            return(awaiter);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }