private void EnumerateSteps() { if (base.Task.IsCompleted) { return; } if (!this.steps.MoveNext()) { this.StepsComplete(); return; } this.currentStep = this.steps.Current; this.currentStep.Task.ContinueWith((System.Threading.Tasks.Task t) => { if (t.IsCanceled) { if (this.currentStep.Policy == IteratorTask <TResult> .ExceptionPolicy.Transfer) { base.TrySetCanceled(); this.StepsComplete(); } return; } if (t.IsFaulted && this.currentStep.Policy == IteratorTask <TResult> .ExceptionPolicy.Transfer) { this.DoSetException(t.Exception.GetBaseException()); this.StepsComplete(); return; } try { this.EnumerateSteps(); } catch (Exception exception1) { Exception exception = exception1; if (Fx.IsFatal(exception)) { throw; } this.DoSetException(exception); } }, TaskContinuationOptions.ExecuteSynchronously); }
protected IteratorTask <TResult> .TaskStep CallTask(System.Threading.Tasks.Task task, IteratorTask <TResult> .ExceptionPolicy policy = 0) { return(new IteratorTask <TResult> .TaskStep(task, policy)); }
protected IteratorTask <TResult> .TaskStep CallTask <TState>(Func <TState, System.Threading.Tasks.Task> taskFunc, TState state, IteratorTask <TResult> .ExceptionPolicy policy = 0) { System.Threading.Tasks.Task task; if (policy != IteratorTask <TResult> .ExceptionPolicy.Continue) { task = taskFunc(state); } else { try { task = taskFunc(state); } catch (Exception exception1) { Exception exception = exception1; if (Fx.IsFatal(exception)) { throw; } TaskCompletionSource <object> taskCompletionSource = new TaskCompletionSource <object>(); taskCompletionSource.SetException(exception); task = taskCompletionSource.Task; } } return(new IteratorTask <TResult> .TaskStep(task, policy)); }
public TaskStep(System.Threading.Tasks.Task task, IteratorTask <TResult> .ExceptionPolicy policy) { this.task = task; this.policy = policy; }