async processStepDecision()

in components/base-workflow/packages/workflow-engine/lib/step/step-loop.js [241:292]


  async processStepDecision(possibleDecision) {
    let decision = possibleDecision;
    let msg;

    if (_.isEmpty(possibleDecision)) {
      await this.callOnPass();
      return this.passDecision();
    }

    // lets start with the possibility that a step is returning a wait builder instance instead of an instance of a wait decision
    if (_.isFunction(possibleDecision.toWaitDecision)) {
      decision = possibleDecision.toWaitDecision();
    }
    // if not wait builder, check if the step returned an instance of pause decision builder instead of an instance
    // of pause decision
    if (_.isFunction(possibleDecision.toPauseDecision)) {
      decision = possibleDecision.toPauseDecision();
    }

    if (WaitDecision.is(decision)) {
      msg = `StepLoop - adding a wait decision for ${decision.seconds} seconds to the step loop decision queue`;
      await this.safeFireEvent('stepLoopQueueAdd', msg, decision);
      this.decisionQueue.push(decision);
      return this.waitDecision(decision.seconds);
    }

    if (PauseDecision.is(decision)) {
      msg = `StepLoop - adding a pause decision for ${decision.seconds} seconds to the step loop decision queue`;
      await this.safeFireEvent('stepLoopQueueAdd', msg, decision);
      await this.safeFireEvent('stepLoopStepPausing', decision.pauseReason);
      this.decisionQueue.push(decision);
      return this.pauseDecision(decision.seconds);
    }

    if (CallDecision.is(decision)) {
      msg = `StepLoop - adding a call decision for ${decision.methodName}() to the step loop decision queue`;
      await this.safeFireEvent('stepLoopQueueAdd', msg, decision);
      this.decisionQueue.push(decision);
      return this.loopDecision();
    }

    if (GoToDecision.is(decision)) {
      msg = `StepLoop - adding a goto decision to execute workflow from step at index ${decision.stepIndex} to the step loop decision queue`;
      await this.safeFireEvent('stepLoopQueueAdd', msg, decision);
      await this.safeFireEvent('stepLoopRequestingGoTo', decision.stepIndex);

      this.decisionQueue.push(decision);
      return this.goToDecision(decision.stepIndex);
    }

    throw new Error(`The step returned an unsupported decision/return object "${JSON.stringify(decision)}".`);
  }