Skip to content

Commit

Permalink
add workflow to client doc (#657)
Browse files Browse the repository at this point in the history
Signed-off-by: Hannah Hunter <[email protected]>
  • Loading branch information
hhunter-ms authored Dec 10, 2024
1 parent 31346f0 commit 7c63bb9
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions daprdocs/content/en/go-sdk-docs/go-client/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,49 @@ if res.Error != nil {

For a full guide on pub/sub, visit [How-To: Publish & subscribe]({{< ref howto-publish-subscribe.md >}}).

### Workflow

You can create [workflows]({{< ref workflow-overview.md >}}) using the Go SDK. For example, start with a simple workflow activity:

```go
func TestActivity(ctx workflow.ActivityContext) (any, error) {
var input int
if err := ctx.GetInput(&input); err != nil {
return "", err
}

// Do something here
return "result", nil
}
```

Write a simple workflow function:

```go
func TestWorkflow(ctx *workflow.WorkflowContext) (any, error) {
var input int
if err := ctx.GetInput(&input); err != nil {
return nil, err
}
var output string
if err := ctx.CallActivity(TestActivity, workflow.ActivityInput(input)).Await(&output); err != nil {
return nil, err
}
if err := ctx.WaitForExternalEvent("testEvent", time.Second*60).Await(&output); err != nil {
return nil, err
}

if err := ctx.CreateTimer(time.Second).Await(nil); err != nil {
return nil, nil
}
return output, nil
}
```

Then compose your application that will use the workflow you've created. [Refer to the How-To: Author workflows guide]({{< ref howto-author-workflow.md >}}) for a full walk-through.

Try out the [Go SDK workflow example.](https://github.com/dapr/go-sdk/blob/main/examples/workflow)

### Output Bindings


Expand Down

0 comments on commit 7c63bb9

Please sign in to comment.