Skip to content

Commit b0b0e87

Browse files
committed
waitForEvent more
1 parent 81fa8f4 commit b0b0e87

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

src/content/docs/workflows/build/events-and-parameters.mdx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Store state durably by returning it from your `step.do` callbacks.
3030

3131
:::
3232

33+
<TypeScriptExample>
34+
3335
```ts
3436
export default {
3537
async fetch(req: Request, env: Env) {
@@ -52,6 +54,8 @@ export default {
5254
};
5355
```
5456

57+
</TypeScriptExample>
58+
5559
To pass parameters via the `wrangler` command-line interface, pass a JSON string as the second parameter to the `workflows trigger` sub-command:
5660

5761
```sh
@@ -63,7 +67,23 @@ npx wrangler@latest workflows trigger workflows-starter '{"some":"data"}'
6367

6468
### Wait for events
6569

66-
TODO -
70+
A running Workflow can wait for an event (or events) by calling `step.waitForEvent`.
71+
72+
<TypeScriptExample>
73+
74+
```ts
75+
export class MyWorkflow extends WorkflowEntrypoint<Env, Params> {
76+
async run(event: WorkflowEvent<Params>, step: WorkflowStep) {
77+
// TODO
78+
//
79+
// TODO
80+
}
81+
}
82+
```
83+
84+
</TypeScriptExample>
85+
86+
Visit the [guide on sending data to Workflows] to learn about how to pass event data to a running Workflow, including via HTTP (webhooks) and/or Workers bindings.
6787

6888
## TypeScript and type parameters
6989

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
---
2-
title: Human in the loop
2+
title: Send data to running Workflows
33
pcx_content_type: concept
44
sidebar:
55
order: 7
66
---
77

88
import { WranglerConfig, TypeScriptExample } from "~/components";
99

10+
###

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,31 @@ Terminate a Workflow instance.
404404

405405
* <code>terminate(): Promise&lt;void&gt;</code>
406406

407+
### sendEvent
408+
409+
[Send an event]() to a running Workflow instance.
410+
411+
* <code>sendEvent(): Promise&lt;void&gt;</code>
412+
413+
* `options` - the event `type` and `payload` to send to the Workflow instance. The `type` must match the `type` in
414+
415+
Return `void` on success; throws an exception if the Workflow is not running or is an errored state.
416+
417+
<TypeScriptExample>
418+
419+
```ts
420+
export class MyWorkflow extends WorkflowEntrypoint<Env, Params> {
421+
async run(event: WorkflowEvent<Params>, step: WorkflowStep) {
422+
// TODO
423+
//
424+
// TODO
425+
}
426+
}
427+
```
428+
429+
</TypeScriptExample>
430+
431+
407432
### InstanceStatus
408433

409434
Details the status of a Workflow instance.

0 commit comments

Comments
 (0)