Skip to main content
Creates a hook that can be used to suspend and resume a workflow run with a payload from an external system. Hooks allow external systems to send arbitrary serializable data into a workflow. Each hook has a unique token that external systems use to send data.

Signature

Parameters

HookOptions
Configuration options for the hook.

Returns

Hook<T>
A hook object that can be awaited or iterated over to receive payloads.

Usage

Basic Hook

Create a hook and await a single payload:

Hook with Custom Token

Use a predictable token that external systems can reconstruct:

Hook with Metadata

Attach additional context to the hook:

Iterate Over Multiple Payloads

Receive multiple payloads using async iteration:

Explicit Resource Management

Use the using keyword for automatic disposal:

Manual Disposal

Release the token early:

Notes

  • Can only be called inside a workflow function (with "use workflow")
  • Hooks implement AsyncIterable and can be used with for await...of
  • Hooks implement the TC39 Explicit Resource Management proposal
  • The token must be unique across all active hooks in your workflow runs
  • Disposing a hook allows another workflow to register a hook with the same token