in step_builder.go [105:151]
func StepAfterBoth[JT, PT1, PT2, ST any](j *JobDefinition[JT], stepName string, parentStep1 *StepDefinition[PT1], parentStep2 *StepDefinition[PT2], stepAfterBothFuncCreator func(input JT) asynctask.AfterBothFunc[PT1, PT2, ST], optionDecorators ...ExecutionOptionPreparer) (*StepDefinition[ST], error) {
if err := addStepPreCheck(j, stepName); err != nil {
return nil, err
}
// compiler not allow me to compare parentStep1 and parentStep2 directly with different genericType
if parentStep1.GetName() == parentStep2.GetName() {
return nil, ErrDuplicateInputParentStep.WithMessage(MsgDuplicateInputParentStep)
}
stepD := newStepDefinition[ST](stepName, stepTypeTask, append(optionDecorators, ExecuteAfter(parentStep1), ExecuteAfter(parentStep2))...)
precedingDefSteps, err := getDependsOnSteps(j, stepD.DependsOn())
if err != nil {
return nil, err
}
stepD.instanceCreator = func(ctx context.Context, ji JobInstanceMeta) StepInstanceMeta {
// TODO: error is ignored here
precedingInstances, precedingTasks, _ := getDependsOnStepInstances(stepD, ji)
jiStrongTyped := ji.(*JobInstance[JT])
stepFunc := stepAfterBothFuncCreator(jiStrongTyped.input)
stepFuncWithPanicHandling := func(ctx context.Context, pt1 PT1, pt2 PT2) (result ST, err error) {
// handle panic from user code
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("panic cought: %v, StackTrace: %s", r, debug.Stack())
}
}()
result, err = stepFunc(ctx, pt1, pt2)
return result, err
}
parentStepInstance1 := getStrongTypedStepInstance(parentStep1, ji)
parentStepInstance2 := getStrongTypedStepInstance(parentStep2, ji)
stepInstance := newStepInstance(stepD, ji)
// here AfterBoth may not invoke instrumentedStepAfterBoth at all, if parentStep1 or parentStep2 returns error.
stepInstance.task = asynctask.AfterBoth(ctx, parentStepInstance1.task, parentStepInstance2.task, instrumentedStepAfterBoth(stepInstance, precedingTasks, stepFuncWithPanicHandling))
ji.addStepInstance(stepInstance, precedingInstances...)
return stepInstance
}
if err := j.addStep(stepD, precedingDefSteps...); err != nil {
return nil, err
}
return stepD, nil
}