Skip to content

Commit 01ea2a8

Browse files
authored
workflows: run return signature (cloudflare#19329)
1 parent e434d33 commit 01ea2a8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/content/docs/workflows/build/workers-api.mdx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,27 @@ export class MyWorkflow extends WorkflowEntrypoint<Env, Params> {
2222
};
2323
```
2424

25+
### run
26+
2527
* <code>run(event: WorkflowEvent&lt;T&gt;, step: WorkflowStep): Promise&lt;T&gt;</code>
2628

2729
* `event` - the event passed to the Workflow, including an optional `payload` containing data (parameters)
2830
* `step` - the `WorkflowStep` type that provides the step methods for your Workflow
2931

32+
The `run` method can optionally return data, which is available when querying the instance status via the [Workers API](/workflows/build/workers-api/#instancestatus), [REST API](/api/resources/workflows/subresources/instances/subresources/status/) and the Workflows dashboard. This can be useful if your Workflow is computing a result, returning the key to data stored in object storage, or generating some kind of identifier you need to act on.
33+
34+
```ts
35+
export class MyWorkflow extends WorkflowEntrypoint<Env, Params> {
36+
async run(event: WorkflowEvent<Params>, step: WorkflowStep) {
37+
// Steps here
38+
let someComputedState = step.do("my step", async () => { })
39+
40+
// Optional: return state from our run() method
41+
return someComputedState
42+
}
43+
};
44+
```
45+
3046
The `WorkflowEvent` type accepts an optional [type parameter](https://www.typescriptlang.org/docs/handbook/2/generics.html#working-with-generic-type-variables) that allows you to provide a type for the `payload` property within the `WorkflowEvent`.
3147

3248
Refer to the [events and parameters](/workflows/build/events-and-parameters/) documentation for how to handle events within yur Workflow code.

0 commit comments

Comments
 (0)