public static Delay ( int millisecondTimeout ) : System.Threading.Tasks.Task | ||
millisecondTimeout | int | |
return | System.Threading.Tasks.Task |
void BackgroundToBackgroundException() { var task1 = UnityTask.Run(() => { Debug.Log("1 Go"); var task2 = UnityTask.Run(() => { UnityTask.Delay(100); Debug.Log("2 Go"); throw new Exception("2 Fail"); }); task2.Wait(); if (task2.IsFaulted) { throw task2.Exception; } }); task1.Wait(); Debug.Log(task1.Status + " " + task1.Exception.Message); }
void Background() { UnityTask.Run(() => { Debug.Log("Sleeping..."); UnityTask.Delay(2000); Debug.Log("Slept"); }); }
void MainTest() { UnityTask.RunOnMain(() => { Debug.Log("Sleeping..."); UnityTask.Delay(2000); Debug.Log("Slept"); }); }
/// <summary> /// Waits for the task to complete /// </summary> public static T Wait <T>(this T self) where T : UnityTask { UnityTask.Delay(10); while (self.keepWaiting) { UnityTask.Delay(10); } return(self); }
void BackgroundToRotine() { UnityTask.Run(() => { Debug.Log("Thread A Running"); var task = UnityTask.RunCoroutine(RoutineFunction()); while (task.IsRunning) { Debug.Log("."); UnityTask.Delay(500); } Debug.Log("Thread A Done"); }); }
void BackgroundToMain() { UnityTask.Run(() => { Debug.Log("Thread A Running"); var task = UnityTask.RunOnMain(() => { Debug.Log("Sleeping..."); UnityTask.Delay(2000); Debug.Log("Slept"); }); while (task.IsRunning) { Debug.Log("."); UnityTask.Delay(100); } Debug.Log("Thread A Done"); }); }