@@ -1219,7 +1219,21 @@ func (c *dbosContext) RunAsStep(_ DBOSContext, fn StepFunc, opts ...StepOption)
12191219 return stepOutput , stepError
12201220}
12211221
1222- // TODO: Add docs --- will add once I get the implementation right
1222+ // Go runs a step inside a Go routine and returns a channel to receive the result.
1223+ // Go generates a deterministic step ID for the step before running the step in a routine, since routines are not deterministic.
1224+ // The step ID is used to track the steps within the same workflow and use the step ID to perform recovery.
1225+ // The folliwing examples shows how to use Go:
1226+ //
1227+ // resultChan, err := dbos.Go(ctx, func(ctx context.Context) (string, error) {
1228+ // return "Hello, World!", nil
1229+ // })
1230+ //
1231+ // resultChan := <-resultChan // wait for the channel to receive
1232+ // if resultChan.err != nil {
1233+ // // Handle error
1234+ // }
1235+ // result := resultChan.result
1236+ //
12231237func Go [R any ](ctx DBOSContext , fn Step [R ], opts ... StepOption ) (chan stepOutcome [R ], error ) {
12241238 // create a determistic step ID
12251239 stepName := runtime .FuncForPC (reflect .ValueOf (fn ).Pointer ()).Name ()
@@ -1230,7 +1244,7 @@ func Go[R any](ctx DBOSContext, fn Step[R], opts ...StepOption) (chan stepOutcom
12301244 stepID := wfState .nextStepID ()
12311245 opts = append (opts , WithNextStepID (stepID ))
12321246
1233- // run step inside a Go routine by passing stepID
1247+ // run step inside a Go routine by passing a stepID
12341248 result := make (chan stepOutcome [R ], 1 )
12351249 go func () {
12361250 res , err := RunAsStep (ctx , fn , opts ... )
0 commit comments