public void Complete(Exception exception) { _exception = exception; isCompleted = true; if (_continuation != null) { UnityTaskUtil.RunOnUnityThread(_continuation); } }
public IEnumerator RunOnUnityThread() { bool checkOne = false; bool checkTwo = false; //Post the first check to the context UnityTaskUtil.RunOnUnityThread(() => { checkOne = UnityTaskUtil.CurrentThreadIsUnityThread; }); //Wait a frame so it has a chance to run yield return(null); var task = Task.Run(() => { UnityTaskUtil.RunOnUnityThread(() => { checkTwo = UnityTaskUtil.CurrentThreadIsUnityThread; }); }); //Wait for the task to run and post the function to the context task.Wait(); //Wait a frame for the posted function to get called on the unity context yield return(null); Assert.IsTrue(checkOne); Assert.IsTrue(checkTwo); }
/// <summary> /// Use this method to start a coroutine from any thread. /// Coroutines themselves always run on the main thread /// </summary> /// <param name="enumerator">coroutine to run</param> public static void Start(IEnumerator enumerator) { UnityTaskUtil.RunOnUnityThread(() => Run(enumerator, cancellationTokenSource.Token)); }
/// <summary> /// Use this method to start a coroutine from any thread. /// Coroutines themselves always run on the main thread /// </summary> /// <param name="enumerator">coroutine to run</param> public static void Start(IEnumerator enumerator) { UnityTaskUtil.RunOnUnityThread(async() => await RunAsync(enumerator, cancellationTokenSource.Token).ConfigureAwait(false)); }