예제 #1
0
        public IEnumerator RunOnUnityThreadAsync()
        {
            var task1 = UnityTaskUtil.RunOnUnityThreadAsync(() => UnityTaskUtil.CurrentThreadIsUnityThread);

            Assert.IsTrue(task1.Result);

            var task2 = Task.Run(() =>
            {
                return(UnityTaskUtil.RunOnUnityThreadAsync(() => UnityTaskUtil.CurrentThreadIsUnityThread).Result);
            });

            //Need to do a coroutine here because task2 waits on the result of the thing running on the main thread
            //so we can't block the main thread till it's done
            yield return(new WaitUntil(() => task2.IsCompleted));

            Assert.IsTrue(task2.Result);
        }
예제 #2
0
 /// <summary>
 /// Use this method when you want to await coroutine completion.
 /// Coroutine itself will always run on the main thread.
 /// </summary>
 /// <param name="routine">coroutine to run</param>
 /// <returns>awaitable task</returns>
 public static async Task RunAsync(IEnumerator routine)
 {
     await UnityTaskUtil.RunOnUnityThreadAsync(() => Run(routine, cancellationTokenSource.Token));
 }
예제 #3
0
 /// <summary>
 /// Use this method when you want to await coroutine completion.
 /// Coroutine itself will always run on the main thread.
 /// </summary>
 /// <param name="routine">coroutine to run</param>
 /// <returns>awaitable task</returns>
 public static async Task RunAsync(IEnumerator routine)
 {
     await UnityTaskUtil.RunOnUnityThreadAsync(async() => await RunAsync(routine, cancellationTokenSource.Token).ConfigureAwait(false));
 }