Skip to content

Commit fc77ff1

Browse files
committed
docs: enhance documentation for Go function, detailing its usage and step ID generation
1 parent b9fe3d8 commit fc77ff1

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

dbos/workflow.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,21 @@ func (c *dbosContext) RunAsStep(_ DBOSContext, fn StepFunc, opts ...StepOption)
11071107
return stepOutput, stepError
11081108
}
11091109

1110-
// TODO: Add docs --- will add once I get the implementation right
1110+
// Go runs a step inside a Go routine and returns a channel to receive the result.
1111+
// Go generates a deterministic step ID for the step before running the step in a routine, since routines are not deterministic.
1112+
// The step ID is used to track the steps within the same workflow and use the step ID to perform recovery.
1113+
// The folliwing examples shows how to use Go:
1114+
//
1115+
// resultChan, err := dbos.Go(ctx, func(ctx context.Context) (string, error) {
1116+
// return "Hello, World!", nil
1117+
// })
1118+
//
1119+
// resultChan := <-resultChan // wait for the channel to receive
1120+
// if resultChan.err != nil {
1121+
// // Handle error
1122+
// }
1123+
// result := resultChan.result
1124+
//
11111125
func Go[R any](ctx DBOSContext, fn Step[R], opts ...StepOption) (chan stepOutcome[R], error) {
11121126
// create a determistic step ID
11131127
stepName := runtime.FuncForPC(reflect.ValueOf(fn).Pointer()).Name()
@@ -1118,7 +1132,7 @@ func Go[R any](ctx DBOSContext, fn Step[R], opts ...StepOption) (chan stepOutcom
11181132
stepID := wfState.NextStepID()
11191133
opts = append(opts, WithNextStepID(stepID))
11201134

1121-
// run step inside a Go routine by passing stepID
1135+
// run step inside a Go routine by passing a stepID
11221136
result := make(chan stepOutcome[R], 1)
11231137
go func() {
11241138
res, err := RunAsStep(ctx, fn, opts...)

0 commit comments

Comments
 (0)