Skip to content

Commit

Permalink
Document workflow initialization considerations for Typescript (#3133)
Browse files Browse the repository at this point in the history
* Clarify initialization order for handlers

* Add advice to Signals section also

* Delete spurious blank line

* Update docs/develop/typescript/message-passing.mdx

* Update docs/develop/typescript/message-passing.mdx

---------

Co-authored-by: Antonio Lain <[email protected]>
Co-authored-by: Erica Sadun <[email protected]>
  • Loading branch information
3 people authored Oct 8, 2024
1 parent eb800b0 commit 7dad257
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/develop/typescript/message-passing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ export async function greetingWorkflow(): Promise<string> {
This allows you to use Activities, Child Workflows, durable [`workflow.sleep`](https://typescript.temporal.io/api/namespaces/workflow#sleep) Timers, [`workflow.condition`](https://typescript.temporal.io/api/namespaces/workflow#condition) conditions, and more.
See [Async handlers](#async-handlers) and [Workflow message passing](/encyclopedia/workflow-message-passing) for guidelines on safely using async Signal and Update handlers.

- Delay calling [`workflow.setHandler`](https://typescript.temporal.io/api/namespaces/workflow#sethandler) until the Workflow initialization needed by Signal (or Update) handlers has finished.
This is safe because the SDK buffers messages when there are no registered handlers for them.
Note that [`workflow.setHandler`](https://typescript.temporal.io/api/namespaces/workflow#sethandler) will immediately invoke the handler of buffered Signals (or Updates) with matching types.
This could lead to out-of-order processing of messages with different types.

- `setHandler` can take `SignalHandlerOptions` (such as `description` and `unfinishedPolicy`) as described in the API reference docs for [`workflow.setHandler`](https://typescript.temporal.io/api/namespaces/workflow#sethandler).


Expand Down Expand Up @@ -196,6 +201,10 @@ wf.setHandler(
This includes the Update ID, which can be useful for deduplication when using Continue-As-New: see [Ensuring your messages are processed exactly once](/encyclopedia/workflow-message-passing#exactly-once-message-processing).
- Update (and Signal) handlers can be `async`, letting them use Activities, Child Workflows, durable [`workflow.sleep`](https://typescript.temporal.io/api/namespaces/workflow#sleep) Timers, [`workflow.condition`](https://typescript.temporal.io/api/namespaces/workflow#condition) conditions, and more.
See [Async handlers](#async-handlers) and [Workflow message passing](/encyclopedia/workflow-message-passing) for safe usage guidelines.
- Delay calling [`workflow.setHandler`](https://typescript.temporal.io/api/namespaces/workflow#sethandler) until the Workflow initialization needed by Update (or Signal) handlers has finished.
This is safe because the SDK buffers messages when there are no registered handlers for them.
Note that [`workflow.setHandler`](https://typescript.temporal.io/api/namespaces/workflow#sethandler) will immediately invoke the handler of buffered Updates (or Signals) with matching types.
This could lead to out-of-order processing of messages with different types.

## Send messages {#send-messages}

Expand Down

0 comments on commit 7dad257

Please sign in to comment.