You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/content/docs/api-reference/workflow/get-writable.mdx
+89-4Lines changed: 89 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,12 +6,12 @@ import { generateDefinition } from "@/lib/tsdoc"
6
6
7
7
# `getWritable()`
8
8
9
-
Retrieves the current workflow run's default writable stream. The writable stream is intended to be passed as an argument to steps which can write to it. Chunks written to this stream can be read outside the workflow by using the `readable` property of the [`Run` object](/docs/api-reference/workflow-api/get-run).
9
+
Retrieves the current workflow run's default writable stream. The writable stream can be used in both workflow and step functions to write data that can be read outside the workflow by using the `readable` property of the [`Run` object](/docs/api-reference/workflow-api/get-run).
10
10
11
-
Use this function in your workflows to produce streaming output that can be consumed by clients in real-time.
11
+
Use this function in your workflows and steps to produce streaming output that can be consumed by clients in real-time.
12
12
13
13
<Callouttype="warn">
14
-
This function can only be called inside a workflow function (functions with `"use workflow"` directive)
14
+
This function can only be called inside a workflow or step function (functions with `"use workflow"` or `"use step"` directive)
15
15
</Callout>
16
16
17
17
```typescript lineNumbers
@@ -56,7 +56,9 @@ Returns a `WritableStream<W>` where `W` is the type of data you plan to write to
56
56
57
57
## Good to Know
58
58
59
-
- The stream should typically be passed to step functions for writing.
59
+
- The stream can be obtained from either workflow or step functions using the same `getWritable()` call.
60
+
- When called from a workflow, the stream can be passed as an argument to steps.
61
+
- When called from a step, it retrieves the same workflow-scoped stream directly.
60
62
- Always release the writer lock after writing to prevent resource leaks.
61
63
- The stream can write binary data (using `TextEncoder`) or structured objects.
62
64
- Remember to close the stream when finished to signal completion.
@@ -100,6 +102,89 @@ async function stepCloseOutputStream(writable: WritableStream) {
100
102
}
101
103
```
102
104
105
+
### Calling `getWritable()` Inside Steps
106
+
107
+
You can also call `getWritable()` directly inside step functions without passing it as a parameter:
0 commit comments