Creating Service Stubs
Before calling a service, create a stub using thenewService() method:
Synchronous Calls
The simplest way to call a service is synchronously. The workflow waits for the service to complete before continuing:Asynchronous Calls with dispatch()
For parallel execution or when you don’t need the result immediately, usedispatch() to call services asynchronously:
Working with Deferred Objects
When you calldispatch(), you get a Deferred<T> object that represents the future result.
await()
Callawait() to get the result (blocks until complete):
status()
Check the status of a deferred operation:Convenience Status Methods
Parallel Execution
Dispatch multiple tasks and wait for all to complete:Combining Deferred with AND
Useand() to wait for multiple deferred objects to complete:
Racing with OR
Useor() to wait for the first deferred to complete:
Service Stubs with Tags
Route service calls to specific workers using tags:Service Stubs with Metadata
Pass metadata with service calls for tracing or context:Void Methods
For service methods that returnvoid or Unit, use dispatchVoid():
Error Handling
Service errors propagate to the workflow. Handle them with try-catch:Best Practices
Use async dispatch for parallel operations
Use async dispatch for parallel operations
When tasks don’t depend on each other, dispatch them in parallel:
Create service stubs as properties
Create service stubs as properties
Initialize service stubs once as class properties:
Don't store Deferred objects as properties
Don't store Deferred objects as properties
Use deferred objects locally within methods:
Use tags for routing
Use tags for routing
Next Steps
Sub-workflows
Learn how to call workflows from workflows
Channels
Receive external signals during execution
Timers
Add delays and timeouts
Workflow Methods
Complete method reference