/// <summary> /// Resolve task safe /// </summary> private void InitNextTask() { //try get next task try { IPandaTask continuationPandaTask = _nextActionDelegate(); //no task resolved if (continuationPandaTask != null) { _state = ContinuationTaskState.WaitSecondComplete; continuationPandaTask.Done(HandleTaskCompleted).Fail(HandleTaskFailed); } else { RejectInternal(new NullReferenceException(@"Continuation callback returns null task!")); } } catch (Exception ex) { if (Status != PandaTaskStatus.Pending) { throw; } //reject on non system exceptions RejectInternal(ex); } }
internal ContinuationTaskFromPandaTask(IPandaTask currentPandaTask, Func <IPandaTask> nextAction, bool fromCatch = false) { //check - set if (currentPandaTask == null) { throw new ArgumentNullException(nameof(currentPandaTask)); } FromCatch = fromCatch; _nextActionDelegate = nextAction ?? throw new ArgumentNullException(nameof(nextAction)); //start listen task. switch (Status) { case PandaTaskStatus.Pending: currentPandaTask.Done(HandleTaskCompleted).Fail(HandleTaskFailed); break; //no allocations for completed tasks case PandaTaskStatus.Rejected: HandleTaskFailed(currentPandaTask.Error); break; case PandaTaskStatus.Resolved: HandleTaskCompleted(); break; } }
public void OnCompleted(Action continuation) { _task.Done(continuation).Fail(_ => continuation()); }