Пример #1
0
 /// <summary>
 /// 作为后台线程
 /// </summary>
 /// <param name="p_task"></param>
 /// <returns></returns>
 public static UnityTask <T> AsForeground <T>(this Task <T> p_task)
 {
     return(p_task.ContinueToForeground(t =>
     {
         if (t.IsFaulted)
         {
             return UnityTask.FromException <T>(t.Exception);
         }
         else
         {
             return UnityTask.FromResult(t.Result);
         }
     }).Unwrap());
 }
Пример #2
0
 /// <summary>
 /// Registers a continuation for the task that will run when the task is complete.
 /// </summary>
 /// <param name="continuation">The continuation to run after the task completes.
 /// The function takes the completed task as an argument.</param>
 /// <returns>A new Task that is complete after both the task and the continuation are
 /// complete.</returns>
 public UnityTask ContinueWith(Action <UnityTask <T> > p_continuation)
 {
     return(base.ContinueWith(t =>
     {
         //if (t.IsFaulted)
         //{
         //    return UnityTask.FromException<int>(t.Exception);
         //}
         //else
         //{
         try
         {
             p_continuation((UnityTask <T>)t);
             return UnityTask.FromResult(0);
         }
         catch (Exception ex)
         {
             return UnityTask.FromException <int>(ex);
         }
         //}
     }));
 }
Пример #3
0
 /// <summary>
 /// Registers a continuation for the task that will run when the task is complete.
 /// </summary>
 /// <param name="continuation">The continuation to run after the task completes.
 /// The function takes the completed task as an argument.</param>
 /// <returns>A new Task that is complete after both the task and the continuation are
 /// complete.</returns>
 public UnityTask <T2> ContinueWith <T2>(Func <UnityTask <T>, T2> p_continuation)
 {
     return(base.ContinueWith(t =>
     {
         //if (t.IsFaulted)
         //{
         //    return UnityTask.FromException<T2>(t.Exception);
         //}
         //else
         //{
         try
         {
             T2 result = p_continuation((UnityTask <T>)t);
             return UnityTask.FromResult(result);
         }
         catch (Exception ex)
         {
             return UnityTask.FromException <T2>(ex);
         }
         //}
     }).Unwrap());
 }
Пример #4
0
 /// <summary>
 /// 作为Unity主线程
 /// </summary>
 /// <param name="task">一个<see cref="T:System.Threading.Tasks.Task`1" />任务</param>
 /// <returns></returns>
 public static UnityTask <TResult> AsForeground <TResult>(this Task <TResult> task)
 {
     return(task.ContinueToForeground(p =>
                                      p.IsFaulted ? UnityTask.FromException <TResult>(p.Exception) : UnityTask.FromResult(p.Result)).Unwrap());
 }
Пример #5
0
 /// <summary>
 /// 作为Unity主线程
 /// </summary>
 /// <param name="task">一个<see cref="T:System.Threading.Tasks.Task" />任务</param>
 /// <returns></returns>
 public static UnityTask AsForeground(this Task task)
 {
     return(task.ContinueToForeground(p =>
                                      p.IsFaulted ? UnityTask.FromException <int>(p.Exception) : UnityTask.FromResult(0)).Unwrap());
 }