This example shows how to pass results to the next vertex or the dag caller.
()
| 10 | |
| 11 | // This example shows how to pass results to the next vertex or the dag caller. |
| 12 | func ExampleDAG_run() { |
| 13 | d := dag.New() |
| 14 | v1 := d.AddVertex(func(ctx context.Context) error { |
| 15 | ctxmeta.GetBaggage(ctx).Set("v1Result", "foo") |
| 16 | return nil |
| 17 | }) |
| 18 | v2 := d.AddVertex(func(ctx context.Context) error { |
| 19 | v1Result, _ := ctxmeta.GetBaggage(ctx).Get("v1Result") |
| 20 | fmt.Println(v1Result) |
| 21 | return nil |
| 22 | }) |
| 23 | d.AddEdge(v1, v2) |
| 24 | |
| 25 | _, ctx := ctxmeta.Inject(context.Background()) |
| 26 | d.Run(ctx) |
| 27 | |
| 28 | // Output: |
| 29 | // foo |
| 30 | } |