context.run()
executes a piece of custom business logic as a workflow step.
It returns a Promise
, so you can decide how steps execute:
- Sequentially by awaiting them one by one.
- In parallel by awaiting multiple steps together.
Arguments
A unique identifier for the step.
The business logic to run inside this step.
Response
Each step can return a JSON-serializable value—anything from simple primitives to complex objects. The value is JSON-serialized and automatically restored across requests.Avoid returning stateful resources such as database connections or file handles.Instead, return plain data (numbers, strings, arrays, objects) so the result can be safely persisted and restored across workflow executions.
Usage
Because results are JSON-serialized, class instances are restored as plain objects.
This means instance methods will not be available unless you explicitly rehydrate the object.To fix this, you can recreate the instance using Object.assign() or a custom factory: