Skip to main content

Examples

Async Chains

Three-module async chain: auth → permissions → dashboard, with configurable failure rates and retry.

Try it

Loading example…

Click “Start Chain” to begin. Adjust failure rate sliders to see error propagation and retry behavior. Each step only runs after its predecessor succeeds.

How it works

Three modules form an async chain using after ordering: auth validates the session, permissions loads after auth succeeds, and dashboard loads after permissions.

  1. after ordering loadPermissions uses after: ['auth::validateSession'] to block until auth’s resolver settles; loadDashboard waits for permissions the same way
  2. crossModuleDeps – each step reads facts from its predecessor to check success (auth.isValid, permissions.role)
  3. Error propagation – if auth fails, permissions never evaluates (its after dependency is in rejected state), and dashboard is doubly blocked
  4. Retry – auth uses retry: { attempts: 2, backoff: 'exponential' }. Restarting auth automatically resumes the chain from where it left off

Summary

What: A three-step async chain (auth → permissions → dashboard) with configurable failure rates, retry with exponential backoff, and visual chain status.

How: Each module’s constraint uses after to depend on the previous step’s constraint, plus crossModuleDeps to read success state. The logging and devtools plugins trace the full chain execution.

Why it works: after provides hard ordering guarantees without manual promise chaining. Error propagation is automatic – downstream steps simply never evaluate when upstream fails. Retrying a single step resumes the entire chain.

Source code

// Source file "async-chains.ts" not found

Stay in the loop. Sign up for our newsletter.

We care about your data. We'll never share your email.

Powered by Directive. This signup uses a Directive module with facts, derivations, constraints, and resolvers – zero useState, zero useEffect. Read how it works