From 550f5b504ce957c4969227964c93506b2a3f87dd Mon Sep 17 00:00:00 2001 From: shentongmartin Date: Fri, 14 Nov 2025 14:08:24 +0800 Subject: [PATCH] fix(workflow): control only example remove wrong AddDependency call (#130) Change-Id: Ibfc1c9e5b25988cd0517820d7225213feca7677d --- .../workflow/4_control_only_branch/main.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/compose/workflow/4_control_only_branch/main.go b/compose/workflow/4_control_only_branch/main.go index a75fe90..0d9d2e6 100644 --- a/compose/workflow/4_control_only_branch/main.go +++ b/compose/workflow/4_control_only_branch/main.go @@ -55,11 +55,23 @@ func main() { return in + 2.0, nil } + announcer := func(ctx context.Context, in any) (any, error) { + logs.Infof("bidder1 had lodged his bid!") + return nil, nil + } + wf := compose.NewWorkflow[float64, map[string]float64]() wf.AddLambdaNode("b1", compose.InvokableLambda(bidder1)). AddInput(compose.START) + // just add a node to announce bidder1 had lodged his bid! + // It should be executed strictly after bidder1, so we use `AddDependency("b1")`. + // Note that `AddDependency()` will only form control relationship, + // but not data passing relationship. + wf.AddLambdaNode("announcer", compose.InvokableLambda(announcer)). + AddDependency("b1") + // add a branch just like adding branch in Graph. wf.AddBranch("b1", compose.NewGraphBranch(func(ctx context.Context, in float64) (string, error) { if in > 5.0 { @@ -69,9 +81,10 @@ func main() { }, map[string]bool{compose.END: true, "b2": true})) wf.AddLambdaNode("b2", compose.InvokableLambda(bidder2)). - // b2 executes strictly after b1, but does not rely on b1's output, - // which means b2 depends on b1, but no data passing between them. - AddDependency("b1"). + // b2 executes strictly after b1 (through branch dependency), + // but does not rely on b1's output, + // which means b2 depends on b1 conditionally, + // but no data passing between them. AddInputWithOptions(compose.START, nil, compose.WithNoDirectDependency()) wf.End().AddInput("b1", compose.ToField("bidder1")).