Source/NFX/TaskUtils.cs
/// <summary>
/// Chains task 'first' with task returned by 'next' if first is completed, not cancelled and not faulted.
/// Returns task that completes after task returned by 'next' completes with result from 'next' task
/// </summary>
Chains task 'first' with task returned by 'next' if first is completed, not cancelled and not faulted.
Returns task that completes after task returned by 'next' completes with result from 'next' task
Chains task ' first ' with task returned by ' next ' if first is completed not cancelled and not faulted . Returns task that completes after task returned by ' next ' completes with result from ' next ' task
public static Task<T1> OnOk<T1>(this Task first, Func<Task<T1>> next,
                                TaskContinuationOptions firstOptions = TaskContinuationOptions.ExecuteSynchronously,
                                TaskContinuationOptions nextOptions = TaskContinuationOptions.ExecuteSynchronously)
    {
      var tcs = new TaskCompletionSource<T1>();
      first.ContinueWith(_ =>
      {
        if (first.IsFaulted)
          tcs.TrySetException(first.Exception.InnerExceptions);
        else if (first.IsCanceled)
          tcs.TrySetCanceled();
        else
        {
          try
          {
            var t = next();
            if (t == null)
              tcs.TrySetException( new NFXException(StringConsts.CANNOT_RETURN_NULL_ERROR + typeof(TaskUtils).FullName + ".Then" ));
            else
            {
              t.ContinueWith(__ =>
              {
                if (t.IsFaulted)
                  tcs.TrySetException(first.Exception.InnerExceptions);
                else if (t.IsCanceled)
                  tcs.TrySetCanceled();
                else
                  tcs.TrySetResult(t.Result);
              }, nextOptions);
            }
          }
          catch (Exception ex)
          {
            tcs.TrySetException(ex);
          }
        }
      }, firstOptions);
      return tcs.Task;
    }
public static Task < T1 > OnOk < T1 > ( this Task first , Func < Task < T1 > > next , TaskContinuationOptions firstOptions = TaskContinuationOptions . ExecuteSynchronously , TaskContinuationOptions nextOptions = TaskContinuationOptions . ExecuteSynchronously ) { var tcs = new TaskCompletionSource < T1 > ( ) ; first . ContinueWith ( _ => { if ( first . IsFaulted ) tcs . TrySetException ( first . Exception . InnerExceptions ) ; else if ( first . IsCanceled ) tcs . TrySetCanceled ( ) ; else { try { var t = next ( ) ; if ( t == null ) tcs . TrySetException ( new NFXException ( StringConsts . CANNOT_RETURN_NULL_ERROR + typeof ( TaskUtils ) . FullName + " " ) ) ; else { t . ContinueWith ( __ => { if ( t . IsFaulted ) tcs . TrySetException ( first . Exception . InnerExceptions ) ; else if ( t . IsCanceled ) tcs . TrySetCanceled ( ) ; else tcs . TrySetResult ( t . Result ) ; } , nextOptions ) ; } } catch ( Exception ex ) { tcs . TrySetException ( ex ) ; } } } , firstOptions ) ; return tcs . Task ; }
Chains task 'first' with task returned by 'next' if first is completed, not cancelled and not faulted.
Chains task ' first ' with task returned by ' next ' if first is completed not cancelled and not faulted .
Task
this
next
Func<Task<T1>>
firstOptions
TaskContinuationOptions
nextOptions
TaskContinuationOptions