Deferred<T> class represents a handle to an asynchronous operation in Infinitic. It’s similar to a Promise or Future but integrated with Infinitic’s durable execution model.
Package
Overview
ADeferred is returned when you dispatch a task or workflow. It allows you to:
- Wait for the operation to complete and get the result
- Check the status of the operation
- Combine multiple operations using logical operators
Properties
The unique identifier of the deferred operation (null if not an ID-based step)Example:
Methods
Result Retrieval
Waits for the operation to complete and returns the resultThis method blocks workflow execution until the deferred operation completes or is canceled. If the operation fails, the failure is propagated.Returns: The result of type TThrows: Exception if the operation failedExample:
Status Checking
Gets the current status of the operation without waitingReturns: One of:
DeferredStatus.ONGOING- Still runningDeferredStatus.COMPLETED- Successfully completedDeferredStatus.FAILED- Failed with errorDeferredStatus.CANCELED- Was canceledDeferredStatus.UNKNOWN- Unknown (e.g., invalid ID)
Returns true if the operation is still running
Returns true if the operation completed successfully
Returns true if the operation failed
Returns true if the operation was canceled
Returns true if the operation status is unknown
Combining Operations
Combines this Deferred with another using logical ORThe resulting Deferred completes when either operation completes (whichever finishes first).Parameters:
other: Deferred<out T>- Another deferred of the same type
Combines this Deferred with another using logical ANDThe resulting Deferred completes when both operations complete.Parameters:
other: Deferred<out T>- Another deferred of the same type
Deferred<List<T>> containing results from bothExample:Static Functions
Combines multiple Deferreds using logical ORParameters:
vararg others: Deferred<out T>- Multiple deferred operations
Combines multiple Deferreds using logical ANDParameters:
vararg others: Deferred<out T>- Multiple deferred operations
Deferred<List<T>> that completes when all operations completeExample:Extension Functions
Applies AND to a list of DeferredsExample:
Applies OR to a list of DeferredsExample:
Usage Patterns
Sequential Execution
Parallel Execution with AND
Race Condition with OR
Conditional Execution
Error Handling
Important Notes
- Deferreds should NOT be stored in workflow properties or method arguments
- They are only valid within the workflow method where they are created
- Calling
await()in a workflow is deterministic and resumable - Status checks do not block workflow execution
- Combining operations with
and/oris also deterministic
See Also
- Workflow - For creating and managing Deferreds
- InfiniticClient - For starting workflows that return Deferreds