Skip to content

Resilient Asynchronous Flow

IdentityFlow is built to manage long-running, asynchronous processes with resilience. It ensures that workflows can pause, wait for external events, handle errors, and resume reliably.

export default defineWorkflow(
{
name: 'order-processing'
},
async (flow) => {
// Each step is tracked and can be retried
await flow.do('validate order', async () => {
await validateOrder(flow.params);
});
// Run steps in parallel using Promise.all
// Note: The workflow waits until all promises in Promise.all resolve.
// Handling errors with Promise.allSettled or cancellation with Promise.race
// requires careful consideration within the IdentityFlow model.
await Promise.all([
flow.do('process payment', async () => {
await processPayment(flow.params.payment);
}),
flow.do('check inventory', async () => {
await checkInventory(flow.params.items);
}),
]);
// Handle conditional flows
if (flow.params.requiresShipping) {
await flow.do('arrange shipping', async () => {
await arrangeShipping(flow.params);
});
}
});

Core Resilience Features:

  • Stateful Execution: Workflows maintain their state across asynchronous operations, ensuring they resume exactly where they left off.
  • Built-in Retries: Configure automatic retries for failed steps with customizable delays and backoff strategies.
  • Explicit Error Handling: Use standard try...catch blocks and flow.error() for robust error management and logging.
  • Parallel Processing: Safely execute multiple asynchronous tasks in parallel using Promise.all.

These capabilities allow you to build complex, long-running automations that can withstand transient failures and operate reliably.

Dive deeper into Error Handling strategies.