Skip to content

Commit 0cf465b

Browse files
committed
Add docs
1 parent f629580 commit 0cf465b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,24 @@ func SubWorkflow(ctx workflow.Context, msg string) (int, error) {
423423

424424
Similar to timer cancellation, you can pass a cancelable context to `CreateSubWorkflowInstance` and cancel the sub-workflow that way. Reacting to the cancellation is the same as canceling a workflow via the `Client`. See [Canceling workflows](#canceling-workflows) for more details.
425425

426+
### `ContinueAsNew`
427+
428+
```ContinueAsNew` allows you to restart workflow execution with different inputs. The purpose is to keep the history size small enough to avoid hitting size limits, running out of memory and impacting performance. It works by returning a special `error` from your workflow that contains the new inputs:
429+
430+
```go
431+
wf := func(ctx workflow.Context, run int) (int, error) {
432+
run = run + 1
433+
if run < 3 {
434+
return run, workflow.ContinueAsNew(ctx, run)
435+
}
436+
437+
return run, nil
438+
}
439+
```
440+
441+
Here the workflow is going to be restarted when `workflow.ContinueAsNew` is returned. Internally the new execution starts with a fresh history. It uses the same `InstanceID` but a different `ExecutionID`.
426442

443+
If a sub-workflow is restarted, the caller doesn't notice this, only once it ends without being restarted the caller will get the result and control will be passed back.
427444

428445
### `select`
429446

0 commit comments

Comments
 (0)