public static IAwaiter GetAwaiter(this WaitForMainThread instruction) { CoroutineAwaiter awaiter = new CoroutineAwaiter(); Executors.RunOnMainThread(() => { awaiter.SetResult(null); }); 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); }