<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Cascada Blog</title>
  <subtitle>Concurrency-first scripting and templating for JavaScript and TypeScript. Write familiar, sequential logic. Cascada handles the concurrency.</subtitle>
  <link href="https://cascada.dev/feed.xml" rel="self"/>
  <link href="https://cascada.dev/blog/"/>
  <id>https://cascada.dev/blog/</id>
  <updated>2026-05-05T00:00:00Z</updated>
  <author><name>Angel Popov</name></author>
  
  <entry>
    <title>Implicit async programming model for imperative (JS/Python-like) languages</title>
    <link href="https://cascada.dev/posts/implicit-async-programming/"/>
    <id>https://cascada.dev/posts/implicit-async-programming/</id>
    <updated>2026-05-05T00:00:00Z</updated>
    <summary>CascadaScript brings safe, implicit concurrency to imperative JavaScript and Python-like code: familiar syntax, automatic dependency ordering, deterministic output, and dataflow-based error handling.</summary>
    <content type="html">&lt;h2 id=&quot;asynchronous-programming-is-hard&quot; tabindex=&quot;-1&quot;&gt;Asynchronous Programming Is Hard&lt;/h2&gt;
&lt;p&gt;We tend to think sequentially, but in concurrent code time is the hidden variable that is out of your control. Operations that seem independent race each other in subtle ways. Exceptions pop up detached from the original call site. Shared state changes are a nightmare to coordinate.&lt;/p&gt;
&lt;p&gt;Imperative languages like JavaScript and Python treat concurrency as an opt-in feature. Every &lt;code&gt;await&lt;/code&gt; and every &lt;code&gt;Promise.all&lt;/code&gt; is you doing the scheduler&#39;s job by hand. And you will occasionally get it wrong.&lt;/p&gt;
&lt;p&gt;Other languages build concurrency into their foundations. It becomes safe and predictable by design. But the price is a completely different way of thinking. Not just new syntax - new primitives, new abstractions, a new vocabulary for every idea you already know.&lt;/p&gt;
&lt;p&gt;What if imperative code could keep its familiar syntax, but get safe concurrency by default?&lt;/p&gt;
&lt;h2 id=&quot;familiar-code%2C-implicit-concurrency&quot; tabindex=&quot;-1&quot;&gt;Familiar Code, Implicit Concurrency&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://cascada.dev/cascada-script/&quot;&gt;CascadaScript&lt;/a&gt; is a language that brings safe, implicit concurrency to imperative code. It looks like the JavaScript or Python you already know - functions, loops, plain expressions - but the execution model is radically different.&lt;/p&gt;
&lt;p&gt;Under the hood, every operation that can run concurrently, does: every statement, every part of every expression, every step inside every function call, every iteration of every loop, and all code in each imported script. All of them run at the same time. An operation only waits when it actually depends on another&#39;s result. No special syntax or annotations required.&lt;/p&gt;
&lt;p&gt;Despite execution happening concurrently and out of order, all output - arrays, objects, strings - is always in source-code order. The results are equivalent to sequential execution, only much faster.&lt;/p&gt;
&lt;p&gt;Sequential execution in &lt;a href=&quot;https://cascada.dev/cascada-script/&quot;&gt;CascadaScript&lt;/a&gt; is not something you manage. It emerges naturally from data dependencies. If one operation uses the result of another, it waits. That&#39;s it.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; a = &lt;span class=&quot;token-function&quot;&gt;fetchInput&lt;/span&gt;()
&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; b = &lt;span class=&quot;token-function&quot;&gt;transform&lt;/span&gt;(a)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Cascada knows &lt;code&gt;b&lt;/code&gt; cannot start until &lt;code&gt;a&lt;/code&gt; resolves. No &lt;code&gt;await&lt;/code&gt;, no explicit ordering. Most code that looks sequential already is sequential in the ways that matter - and concurrent in all the ways you&#39;d never have bothered to write by hand.&lt;/p&gt;
&lt;h2 id=&quot;sequential-by-exception&quot; tabindex=&quot;-1&quot;&gt;Sequential by Exception&lt;/h2&gt;
&lt;p&gt;There are cases where imported native functions and objects still need to run in a specific order. Cascada can order its own internal work automatically, but it cannot know whether a context function is pure or has side effects.&lt;/p&gt;
&lt;p&gt;For these external cases, such as writing to a database, interacting with a stateful API, or calling a mutable function, use the &lt;code&gt;!&lt;/code&gt; marker to signal that an external call has side effects on a path. The path must be on the context object. Once any call on a path is marked with &lt;code&gt;!&lt;/code&gt;, all subsequent accesses on that path wait - plain calls, further &lt;code&gt;!&lt;/code&gt; calls, and property reads alike - while the rest of the script continues concurrently. Sequencing is hierarchical: marking &lt;code&gt;db!&lt;/code&gt; sequences all sub-paths such as &lt;code&gt;db.users&lt;/code&gt; and &lt;code&gt;db.accounts&lt;/code&gt; too.&lt;/p&gt;
&lt;p&gt;One example is when &lt;code&gt;db.write(A)&lt;/code&gt; must happen before &lt;code&gt;db.write(B)&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;db!.&lt;span class=&quot;token-function&quot;&gt;write&lt;/span&gt;(A)
db!.&lt;span class=&quot;token-function&quot;&gt;write&lt;/span&gt;(B)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There are two more constructs that add syntactic sugar on top of the &lt;code&gt;!&lt;/code&gt; operator: the &lt;code&gt;each&lt;/code&gt; loop and the &lt;code&gt;sequence&lt;/code&gt; channel.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;each&lt;/code&gt; loop is a sequential variant of &lt;code&gt;for&lt;/code&gt;. Where &lt;code&gt;for&lt;/code&gt; fires all iterations concurrently, &lt;code&gt;each&lt;/code&gt; runs them one at a time. The next iteration only starts after the previous one completes. Use it when iterations have side effects that must not overlap: writing records in order, processing a queue, or running steps that depend on the state left by the previous iteration.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token-keyword&quot;&gt;each&lt;/span&gt; event &lt;span class=&quot;token-keyword&quot;&gt;in&lt;/span&gt; auditEvents
  db!.&lt;span class=&quot;token-function&quot;&gt;write&lt;/span&gt;(event)
  logger!.&lt;span class=&quot;token-function&quot;&gt;append&lt;/span&gt;(&lt;span class=&quot;token-string&quot;&gt;&amp;quot;stored &amp;quot;&lt;/span&gt; + event.id)
&lt;span class=&quot;token-keyword&quot;&gt;endeach&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here every event is written and logged before the next event starts. Other unrelated work in the script can still run concurrently; only this loop is ordered.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;sequence&lt;/code&gt; lets you declare an external object as inherently sequential once. Every call on it will then respect source-code order, no matter where in the script it appears. Use it for connections, streams, or cursors where every interaction must happen in the order written.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;sequence db = services.db

&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; user  = db.&lt;span class=&quot;token-function&quot;&gt;getUser&lt;/span&gt;(&lt;span class=&quot;token-number&quot;&gt;123&lt;/span&gt;)
&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; posts = db.&lt;span class=&quot;token-function&quot;&gt;getPosts&lt;/span&gt;(user.id)
&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; state = db.connectionState

&lt;span class=&quot;token-keyword&quot;&gt;return&lt;/span&gt; {
  user: user,
  posts: posts,
  state: state
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Each read or call through &lt;code&gt;db&lt;/code&gt; waits for the previous one, because the database object is stateful. You do not have to mark every call with &lt;code&gt;!&lt;/code&gt;; the sequence declaration makes the ordered interface explicit once.&lt;/p&gt;
&lt;h2 id=&quot;errors-that-flow-like-data&quot; tabindex=&quot;-1&quot;&gt;Errors That Flow Like Data&lt;/h2&gt;
&lt;p&gt;In concurrent code, the traditional exception handling model breaks down. If multiple operations are running in parallel and one fails, halting everything would discard all the work that succeeded.&lt;/p&gt;
&lt;p&gt;Error-as-value approaches like Rust&#39;s &lt;code&gt;Result&lt;/code&gt; or Go&#39;s error returns fare better, but in ordinary imperative code they still put the burden on you: every call site must explicitly check, unwrap, return, or repair the error. In a concurrent workflow with dozens of parallel operations, that manual plumbing becomes unmanageable - and easy to get wrong.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://cascada.dev/cascada-script/&quot;&gt;CascadaScript&lt;/a&gt; replaces exceptions with &lt;strong&gt;dataflow poisoning&lt;/strong&gt;. A failed operation produces an Error Value that flows forward through your script exactly like any other value. Only operations that depend on it are poisoned, while everything else keeps running unaffected.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; user  = &lt;span class=&quot;token-function&quot;&gt;fetchUser&lt;/span&gt;(&lt;span class=&quot;token-number&quot;&gt;123&lt;/span&gt;)     &lt;span class=&quot;token-comment&quot;&gt;// succeeds&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; posts = &lt;span class=&quot;token-function&quot;&gt;fetchPosts&lt;/span&gt;(&lt;span class=&quot;token-number&quot;&gt;123&lt;/span&gt;)    &lt;span class=&quot;token-comment&quot;&gt;// fails&lt;/span&gt;

&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; postCount = posts.length   &lt;span class=&quot;token-comment&quot;&gt;// becomes an error - depends on posts&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; username  = user.name      &lt;span class=&quot;token-comment&quot;&gt;// fine - independent of posts&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A script only fails if an error reaches what you actually return. Until then, you can detect it with &lt;code&gt;is error&lt;/code&gt; and repair it by reassigning a fallback:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token-keyword&quot;&gt;if&lt;/span&gt; posts &lt;span class=&quot;token-keyword&quot;&gt;is&lt;/span&gt; &lt;span class=&quot;token-keyword&quot;&gt;error&lt;/span&gt;
  posts = []
&lt;span class=&quot;token-keyword&quot;&gt;endif&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This means partial failures are not catastrophic. Unrelated concurrent work completes, and you decide what to do with the parts that failed.&lt;/p&gt;
&lt;p&gt;Poisoning is especially careful around control flow. For example, if an &lt;code&gt;if&lt;/code&gt; condition is itself an Error Value, neither branch runs - and every variable that either branch could have modified becomes poisoned too:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; accessLevel = &lt;span class=&quot;token-string&quot;&gt;&amp;quot;none&amp;quot;&lt;/span&gt;

&lt;span class=&quot;token-keyword&quot;&gt;if&lt;/span&gt; user.isAdmin        &lt;span class=&quot;token-comment&quot;&gt;// user is an error&lt;/span&gt;
  accessLevel = &lt;span class=&quot;token-string&quot;&gt;&amp;quot;full&amp;quot;&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;else&lt;/span&gt;
  accessLevel = &lt;span class=&quot;token-string&quot;&gt;&amp;quot;limited&amp;quot;&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;endif&lt;/span&gt;

&lt;span class=&quot;token-comment&quot;&gt;// accessLevel is now poisoned - not &amp;quot;none&amp;quot;, not stale&lt;/span&gt;
&lt;span class=&quot;token-comment&quot;&gt;// downstream code can detect that something went wrong&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The variable does not silently keep its old value. It becomes an error, so any code that depends on it knows the decision was never made.&lt;/p&gt;
&lt;h2 id=&quot;incremental-output-without-shared-state-chaos&quot; tabindex=&quot;-1&quot;&gt;Incremental Output Without Shared-State Chaos&lt;/h2&gt;
&lt;p&gt;In addition to regular vars and the &lt;code&gt;sequence&lt;/code&gt; channel, &lt;a href=&quot;https://cascada.dev/cascada-script/&quot;&gt;CascadaScript&lt;/a&gt; provides two other channel types: &lt;code&gt;text&lt;/code&gt; and &lt;code&gt;data&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;They are for values you build up incrementally, the same way you would modify any variable. Unlike vars, reading a channel requires &lt;code&gt;.snapshot()&lt;/code&gt;, which waits for all pending changes to settle before returning the value.&lt;/p&gt;
&lt;p&gt;Reach for &lt;code&gt;data&lt;/code&gt; or &lt;code&gt;text&lt;/code&gt; for large structured objects or long assembled texts built up across concurrent operations - cases where a plain var can also work, but would be far less efficient.&lt;/p&gt;
&lt;h2 id=&quot;putting-it-together&quot; tabindex=&quot;-1&quot;&gt;Putting It Together&lt;/h2&gt;
&lt;p&gt;Here is the model in one small script:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; user  = &lt;span class=&quot;token-function&quot;&gt;fetchUser&lt;/span&gt;(userId)   &lt;span class=&quot;token-comment&quot;&gt;// ┐ start immediately,&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; posts = &lt;span class=&quot;token-function&quot;&gt;fetchPosts&lt;/span&gt;(userId)  &lt;span class=&quot;token-comment&quot;&gt;// ┘ run concurrently&lt;/span&gt;

&lt;span class=&quot;token-comment&quot;&gt;// evaluates as soon as &amp;#39;user&amp;#39; resolves - posts may still be fetching&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; role = &lt;span class=&quot;token-string&quot;&gt;&amp;quot;admin&amp;quot;&lt;/span&gt; &lt;span class=&quot;token-keyword&quot;&gt;if&lt;/span&gt; user.isAdmin &lt;span class=&quot;token-keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token-string&quot;&gt;&amp;quot;member&amp;quot;&lt;/span&gt;

&lt;span class=&quot;token-comment&quot;&gt;// every loop iteration runs concurrently&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;data&lt;/span&gt; result
&lt;span class=&quot;token-keyword&quot;&gt;for&lt;/span&gt; post &lt;span class=&quot;token-keyword&quot;&gt;in&lt;/span&gt; posts
  &lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; enriched = &lt;span class=&quot;token-function&quot;&gt;enrichPost&lt;/span&gt;(post)
  result.posts.&lt;span class=&quot;token-function&quot;&gt;push&lt;/span&gt;({
    title:  enriched.title | title,  &lt;span class=&quot;token-comment&quot;&gt;// built-in title-case filter&lt;/span&gt;
    status: &lt;span class=&quot;token-string&quot;&gt;&amp;quot;published&amp;quot;&lt;/span&gt; &lt;span class=&quot;token-keyword&quot;&gt;if&lt;/span&gt; enriched.isLive &lt;span class=&quot;token-keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token-string&quot;&gt;&amp;quot;draft&amp;quot;&lt;/span&gt;
  })
&lt;span class=&quot;token-keyword&quot;&gt;endfor&lt;/span&gt;

&lt;span class=&quot;token-comment&quot;&gt;// ! makes these two sequential with each other, without affecting the rest&lt;/span&gt;
db!.&lt;span class=&quot;token-function&quot;&gt;log&lt;/span&gt;(&lt;span class=&quot;token-string&quot;&gt;&amp;quot;report&amp;quot;&lt;/span&gt;, userId)
db!.&lt;span class=&quot;token-function&quot;&gt;updateLastSeen&lt;/span&gt;(userId)

&lt;span class=&quot;token-keyword&quot;&gt;return&lt;/span&gt; {
  name: user.name,
  role: role,
  posts: result.&lt;span class=&quot;token-function&quot;&gt;snapshot&lt;/span&gt;()
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There is no async ceremony here. The two fetches start together. The role calculation waits only for &lt;code&gt;user&lt;/code&gt;. The loop waits for &lt;code&gt;posts&lt;/code&gt;, then enriches every post concurrently while preserving the final output order. The two database calls are ordered because they touch a stateful external object, but that ordering does not freeze the rest of the script.&lt;/p&gt;
&lt;p&gt;That is the programming model &lt;a href=&quot;https://cascada.dev/cascada-script/&quot;&gt;CascadaScript&lt;/a&gt; is aiming for: ordinary imperative code, automatic concurrency where it is safe, explicit sequencing only where it matters, and deterministic results at the end.&lt;/p&gt;
&lt;p&gt;Unbounded JavaScript and Python will not be able to do this, but we may someday get a constrained dialect that can. &lt;a href=&quot;https://cascada.dev/cascada-script/&quot;&gt;CascadaScript&lt;/a&gt; pushes the envelope on how far this model can go.&lt;/p&gt;
&lt;h2 id=&quot;quick-links&quot; tabindex=&quot;-1&quot;&gt;Quick Links&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://cascada.dev/cascada-script/&quot;&gt;CascadaScript Specification&lt;/a&gt; - the full language reference&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cascada.dev/posts/cascada-script-intro/&quot;&gt;Introduction to CascadaScript&lt;/a&gt; - a fuller walkthrough of the language and its core features&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/geleto/cascada&quot;&gt;Cascada project&lt;/a&gt; - The Cascada GitHub repository - comes in two flavors that share the same execution model: &lt;a href=&quot;https://cascada.dev/cascada-script/&quot;&gt;CascadaScript&lt;/a&gt; - the language, and &lt;a href=&quot;https://cascada.dev/cascada-template/&quot;&gt;Cascada Template&lt;/a&gt; for generating text output.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cascada.dev/posts/cascada-kitchen-chef/&quot;&gt;The Kitchen Chef&#39;s Guide to Taming Chaos&lt;/a&gt; - the intuitive, no-jargon explanation that everyone can understand&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- - [Casai](https://github.com/geleto/casai) - an AI orchestration library built on Cascada for effortless, concurrent agent and workflow design. --&gt;
&lt;!-- - [Casai Examples](https://github.com/geleto/casai-examples) - a collection of practical examples demonstrating AI agent patterns using Casai. --&gt;
</content>
  </entry>
  
  <entry>
    <title>Introduction to CascadaScript: Concurrent by Default, Sequential by Exception</title>
    <link href="https://cascada.dev/posts/cascada-script-intro/"/>
    <id>https://cascada.dev/posts/cascada-script-intro/</id>
    <updated>2026-04-30T00:00:00Z</updated>
    <summary>A scripting language that turns async programming upside down: everything runs concurrently by default, you never write await, and race conditions are impossible by design. Learn how Cascada&#39;s data-driven execution model eliminates async plumbing while maximizing I/O throughput.</summary>
    <content type="html">&lt;h3 id=&quot;cascadascript---everything-runs-at-once&quot; tabindex=&quot;-1&quot;&gt;CascadaScript - Everything Runs at Once&lt;/h3&gt;
&lt;p&gt;CascadaScript is a scripting language where everything runs at once, concurrently - every statement, every part of every expression, every step inside every function call, every iteration of every loop, every task in every imported script - and an operation only waits when it actually depends on another&#39;s result. And the final result is identical to sequential execution - just dramatically faster.&lt;/p&gt;
&lt;p&gt;It is a specialized scripting language designed for orchestrating complex asynchronous workflows in JavaScript and TypeScript applications. It is not a general-purpose programming language - instead, it acts as a data-orchestration layer for coordinating APIs, databases, LLMs, and other I/O-bound operations with maximum concurrency and minimal boilerplate.&lt;/p&gt;
&lt;h4 id=&quot;ordinary-syntax%2C-extraordinary-power&quot; tabindex=&quot;-1&quot;&gt;Ordinary Syntax, Extraordinary Power&lt;/h4&gt;
&lt;p&gt;What makes it extraordinary is how ordinary the syntax looks: instantly familiar to any JavaScript or Python developer. It uses familiar syntax and language constructs while offering language-level support for boilerplate-free concurrent workflows, explicit control over side effects, deterministic output construction, and dataflow-based error handling with recovery rollbacks.&lt;/p&gt;
&lt;p&gt;Cascada is particularly well suited for:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;AI, agents, and LLM orchestration&lt;/strong&gt; - chain prompts, tools, and retrieval calls without juggling promises (see &lt;a href=&quot;https://github.com/geleto/casai&quot;&gt;Casai&lt;/a&gt;, an AI orchestration library built on Cascada)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Data pipelines&lt;/strong&gt; - coordinate parallel stages while keeping the final result deterministic&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ETL workflows&lt;/strong&gt; - write complex extraction, transformation, validation, enrichment, and loading flows in ordinary code that runs concurrently&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;High-throughput I/O coordination&lt;/strong&gt; - squeeze maximum concurrency out of API-heavy workloads&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Cascada is open source - explore the project on &lt;a href=&quot;https://github.com/geleto/cascada&quot;&gt;GitHub&lt;/a&gt;.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;quick-links&quot; tabindex=&quot;-1&quot;&gt;Quick Links&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://cascada.dev/cascada-script/&quot;&gt;CascadaScript Specification&lt;/a&gt; - the full language reference&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cascada.dev/posts/cascada-kitchen-chef/&quot;&gt;The Kitchen Chef&#39;s Guide to Taming Chaos&lt;/a&gt; - the intuitive, no-jargon explanation that everyone can understand&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/geleto/cascada&quot;&gt;Cascada GitHub Repository&lt;/a&gt; - open source · &lt;code&gt;npm install cascada-engine&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/geleto/casai&quot;&gt;Casai&lt;/a&gt; - an AI orchestration library built on Cascada for effortless, concurrent agent and workflow design.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/geleto/casai-examples&quot;&gt;Casai Examples&lt;/a&gt; - a collection of practical examples demonstrating AI agent patterns using Casai.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;
&lt;h3 id=&quot;the-nightmare%3A-why-async-programming-is-so-hard&quot; tabindex=&quot;-1&quot;&gt;The Nightmare: Why Async Programming Is So Hard&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;async/await&lt;/code&gt; is a huge improvement over callback hell. But the moment you want performance, you&#39;re back to being a concurrency expert.&lt;/p&gt;
&lt;p&gt;The fundamental problem: you manually orchestrate what runs when. Which operations can run together? Which must wait? You figure it out yourself, every time.&lt;/p&gt;
&lt;h4 id=&quot;shared-state&quot; tabindex=&quot;-1&quot;&gt;Shared State&lt;/h4&gt;
&lt;p&gt;All operations read and write to shared variables or objects. The complexity explodes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Manual dependency tracking.&lt;/strong&gt; Should operation A &lt;code&gt;await&lt;/code&gt; operation B before updating state? Which operations can safely run concurrently? You trace through every possible execution order in your head.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Get the order wrong: race conditions.&lt;/strong&gt; Operation A reads a value, operation B modifies it, operation A writes based on the stale value. Your state is corrupted.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Over-serialize to be safe?&lt;/strong&gt; Make everything &lt;code&gt;await&lt;/code&gt; everything else to avoid conflicts. Now your concurrent code runs sequentially anyway.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Changes ripple everywhere.&lt;/strong&gt; Add one new operation that touches shared state? Review every other operation to ensure no new conflicts. Your code becomes brittle and impossible to refactor.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;state-machines-%26-batch-synchronization&quot; tabindex=&quot;-1&quot;&gt;State Machines &amp;amp; Batch Synchronization&lt;/h4&gt;
&lt;p&gt;To avoid this complexity, most frameworks use state machines (with chokepoints between states) or batch synchronization (concurrent tasks that must all complete). Simpler to reason about, but: 19 API calls finish in 50ms, one takes 3 seconds. Everything waits at the chokepoint for the slowest operation-and you still manually coordinate the convergence.&lt;/p&gt;
&lt;p&gt;The payoff for getting this right is enormous - optimal orchestration can cut response times in half or more. But the manual complexity? That&#39;s where code breaks.&lt;/p&gt;
&lt;p&gt;What if you could skip the manual orchestration entirely? That&#39;s exactly what &lt;a href=&quot;https://cascada.dev/cascada-script/&quot;&gt;CascadaScript&lt;/a&gt; does.&lt;/p&gt;
&lt;p&gt;Let&#39;s dive into how it flips the script on async programming.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;1.-%E2%9A%A1-concurrent-by-default&quot; tabindex=&quot;-1&quot;&gt;1. ⚡ Concurrent by Default&lt;/h2&gt;
&lt;p&gt;The most fundamental shift in Cascada is that it&#39;s concurrent by default. In most languages, code runs line by line, one after the other. In Cascada, any independent lines of code run at the same time.&lt;/p&gt;
&lt;p&gt;Think about fetching a user&#39;s profile, their preferences, and their analytics. These are three separate operations that don&#39;t depend on each other. In traditional JavaScript, you&#39;d need &lt;code&gt;Promise.all&lt;/code&gt; to run them concurrently. Cascada does it automatically.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token-comment&quot;&gt;// These three operations start at the same time, automatically!&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; user = &lt;span class=&quot;token-function&quot;&gt;fetchUser&lt;/span&gt;(&lt;span class=&quot;token-number&quot;&gt;123&lt;/span&gt;)
&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; preferences = &lt;span class=&quot;token-function&quot;&gt;getUserPreferences&lt;/span&gt;(&lt;span class=&quot;token-number&quot;&gt;123&lt;/span&gt;)
&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; analytics = &lt;span class=&quot;token-function&quot;&gt;getAnalytics&lt;/span&gt;(&lt;span class=&quot;token-number&quot;&gt;123&lt;/span&gt;)

&lt;span class=&quot;token-comment&quot;&gt;// `return` produces the script&amp;#39;s output&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;return&lt;/span&gt; {
  user: user,
  preferences: preferences,
  analytics: analytics
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;No &lt;code&gt;Promise.all&lt;/code&gt;, no &lt;code&gt;await&lt;/code&gt;, no special syntax. If it &lt;em&gt;can&lt;/em&gt; run concurrently, it &lt;em&gt;will&lt;/em&gt;.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;2.-%F0%9F%9A%A6-data-driven-flow%3A-code-runs-when-its-inputs-are-ready&quot; tabindex=&quot;-1&quot;&gt;2. 🚦 Data-Driven Flow: Code Runs When Its Inputs Are Ready&lt;/h2&gt;
&lt;p&gt;You might be thinking, &amp;quot;What if one operation &lt;em&gt;does&lt;/em&gt; depend on another?&amp;quot; Cascada has you covered.&lt;/p&gt;
&lt;p&gt;The engine automatically analyzes the data dependencies in your script. An operation will only run once all the variables it needs are ready. This simple rule guarantees the correct order of execution and completely eliminates race conditions by design.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token-comment&quot;&gt;// 1. This runs first&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; user = &lt;span class=&quot;token-function&quot;&gt;fetchUser&lt;/span&gt;(&lt;span class=&quot;token-number&quot;&gt;123&lt;/span&gt;)

&lt;span class=&quot;token-comment&quot;&gt;// 2. This depends on &amp;#39;user&amp;#39;, so Cascada waits for it to resolve&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; greeting = &lt;span class=&quot;token-string&quot;&gt;&amp;quot;Hello, &amp;quot;&lt;/span&gt; + user.name

&lt;span class=&quot;token-comment&quot;&gt;// 3. Meanwhile, these run concurrently with everything above&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; posts = &lt;span class=&quot;token-function&quot;&gt;fetchPosts&lt;/span&gt;(&lt;span class=&quot;token-number&quot;&gt;123&lt;/span&gt;)
&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; comments = &lt;span class=&quot;token-function&quot;&gt;fetchComments&lt;/span&gt;(&lt;span class=&quot;token-number&quot;&gt;123&lt;/span&gt;)

&lt;span class=&quot;token-keyword&quot;&gt;return&lt;/span&gt; {
  greeting: greeting,
  posts: posts,
  comments: comments
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here, &lt;code&gt;greeting&lt;/code&gt; won&#39;t be calculated until &lt;code&gt;fetchUser(123)&lt;/code&gt; is complete and the &lt;code&gt;user&lt;/code&gt; variable has a value. But &lt;code&gt;posts&lt;/code&gt; and &lt;code&gt;comments&lt;/code&gt; start fetching immediately since they don&#39;t depend on &lt;code&gt;user&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;No more subtle timing bugs that only appear in production. The engine orchestrates everything automatically.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;3.-%E2%9C%A8-no-more-await%3A-just-use-your-values&quot; tabindex=&quot;-1&quot;&gt;3. ✨ No More &lt;code&gt;await&lt;/code&gt;: Just Use Your Values&lt;/h2&gt;
&lt;p&gt;This is where the magic really happens. Notice the lack of &lt;code&gt;await&lt;/code&gt; in the examples above? In Cascada, you never have to think about whether a variable holds a value or a promise. You just use it.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token-comment&quot;&gt;// Traditional JavaScript: Promise hell&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;const&lt;/span&gt; userPromise = &lt;span class=&quot;token-function&quot;&gt;fetchUser&lt;/span&gt;(&lt;span class=&quot;token-number&quot;&gt;123&lt;/span&gt;);
&lt;span class=&quot;token-keyword&quot;&gt;const&lt;/span&gt; name = &lt;span class=&quot;token-keyword&quot;&gt;await&lt;/span&gt; userPromise.name; &lt;span class=&quot;token-comment&quot;&gt;// Wait, can&amp;#39;t do this!&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;const&lt;/span&gt; actualUser = &lt;span class=&quot;token-keyword&quot;&gt;await&lt;/span&gt; userPromise;
&lt;span class=&quot;token-keyword&quot;&gt;const&lt;/span&gt; name = actualUser.name; &lt;span class=&quot;token-comment&quot;&gt;// Finally!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Cascada makes this completely invisible:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token-comment&quot;&gt;// Cascada: Just use it&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; user = &lt;span class=&quot;token-function&quot;&gt;fetchUser&lt;/span&gt;(&lt;span class=&quot;token-number&quot;&gt;123&lt;/span&gt;)

&lt;span class=&quot;token-keyword&quot;&gt;return&lt;/span&gt; {
  greeting: &lt;span class=&quot;token-string&quot;&gt;&amp;quot;Hello, &amp;quot;&lt;/span&gt; + user.name,
  email: user.email,
  status: &lt;span class=&quot;token-string&quot;&gt;&amp;quot;active&amp;quot;&lt;/span&gt; &lt;span class=&quot;token-keyword&quot;&gt;if&lt;/span&gt; user.isActive &lt;span class=&quot;token-keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token-string&quot;&gt;&amp;quot;inactive&amp;quot;&lt;/span&gt;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Forget &lt;code&gt;.then()&lt;/code&gt; and forget manually tracking promises. Cascada handles the asynchronous state invisibly under the hood. You can pass a &amp;quot;future value&amp;quot; (a promise) into a function or use it in an expression, and it just works.&lt;/p&gt;
&lt;p&gt;This lets you focus entirely on your business logic, not the async plumbing.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;4.-%F0%9F%93%8B-from-chaos-to-order%3A-channels&quot; tabindex=&quot;-1&quot;&gt;4. 📋 From Chaos to Order: Channels&lt;/h2&gt;
&lt;p&gt;So far we&#39;ve used a simple &lt;code&gt;return&lt;/code&gt; to produce output. But what happens when concurrent code needs to &lt;em&gt;contribute&lt;/em&gt; to the output? Imagine fetching three users at once and collecting their names:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; userIds = [&lt;span class=&quot;token-number&quot;&gt;101&lt;/span&gt;, &lt;span class=&quot;token-number&quot;&gt;102&lt;/span&gt;, &lt;span class=&quot;token-number&quot;&gt;103&lt;/span&gt;]
&lt;span class=&quot;token-comment&quot;&gt;// We want all three fetched concurrently - but how do we collect the results in order?&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In a traditional concurrent loop, you&#39;d push to a shared array and pray the order works out. In Cascada, you reach for a channel.&lt;/p&gt;
&lt;p&gt;Most of the time, a regular &lt;code&gt;var&lt;/code&gt; is exactly what you want: assign a value, compose an object, change it a bit, pass it around, and return it. &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;data&lt;/code&gt;, and &lt;code&gt;text&lt;/code&gt; can all be used to build values incrementally. The main visible difference is that a &lt;code&gt;var&lt;/code&gt; is read directly, while a channel is read with &lt;code&gt;.snapshot()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;That snapshot step matters when several concurrent branches contribute to one growing output - an array of results, a nested JSON object, or a long text report. A &lt;code&gt;data&lt;/code&gt; or &lt;code&gt;text&lt;/code&gt; channel is a declared output builder: you write to it from anywhere, including concurrent loop iterations, and &lt;code&gt;.snapshot()&lt;/code&gt; waits for all pending changes to settle before returning the materialized value.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; userIds = [&lt;span class=&quot;token-number&quot;&gt;101&lt;/span&gt;, &lt;span class=&quot;token-number&quot;&gt;102&lt;/span&gt;, &lt;span class=&quot;token-number&quot;&gt;103&lt;/span&gt;]

&lt;span class=&quot;token-comment&quot;&gt;// Declare a data channel&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;data&lt;/span&gt; result

&lt;span class=&quot;token-comment&quot;&gt;// All three fetchUserDetails calls run concurrently.&lt;/span&gt;
&lt;span class=&quot;token-comment&quot;&gt;// Maybe user 103&amp;#39;s data comes back first - that&amp;#39;s fine.&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;for&lt;/span&gt; id &lt;span class=&quot;token-keyword&quot;&gt;in&lt;/span&gt; userIds
  &lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; details = &lt;span class=&quot;token-function&quot;&gt;fetchUserDetails&lt;/span&gt;(id)
  result.users.&lt;span class=&quot;token-function&quot;&gt;push&lt;/span&gt;(details.name)
&lt;span class=&quot;token-keyword&quot;&gt;endfor&lt;/span&gt;

&lt;span class=&quot;token-comment&quot;&gt;// `snapshot()` materializes the channel into a value&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;return&lt;/span&gt; result.&lt;span class=&quot;token-function&quot;&gt;snapshot&lt;/span&gt;()
&lt;span class=&quot;token-comment&quot;&gt;// { &amp;quot;users&amp;quot;: [&amp;quot;Alice&amp;quot;, &amp;quot;Bob&amp;quot;, &amp;quot;Charlie&amp;quot;] } - always in this order&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Cascada provides two built-in channel types:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;data&lt;/code&gt;&lt;/strong&gt; - for incrementally building structured objects and arrays. Supports &lt;code&gt;.push()&lt;/code&gt;, &lt;code&gt;.merge()&lt;/code&gt;, property assignment, arithmetic operators, and more. Reach for it when concurrent work contributes to one JSON-shaped result.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;text&lt;/code&gt;&lt;/strong&gt; - for incrementally assembling strings. Calls like &lt;code&gt;log(&amp;quot;hello&amp;quot;)&lt;/code&gt; append text in source-code order, perfect for streaming, transcripts, logs, or reports.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;text log
&lt;span class=&quot;token-function&quot;&gt;log&lt;/span&gt;(&lt;span class=&quot;token-string&quot;&gt;&amp;quot;Starting import&#92;n&amp;quot;&lt;/span&gt;)
&lt;span class=&quot;token-keyword&quot;&gt;for&lt;/span&gt; user &lt;span class=&quot;token-keyword&quot;&gt;in&lt;/span&gt; users
  &lt;span class=&quot;token-function&quot;&gt;log&lt;/span&gt;(&lt;span class=&quot;token-string&quot;&gt;&amp;quot;Imported: &amp;quot;&lt;/span&gt; + user.name + &lt;span class=&quot;token-string&quot;&gt;&amp;quot;&#92;n&amp;quot;&lt;/span&gt;)
&lt;span class=&quot;token-keyword&quot;&gt;endfor&lt;/span&gt;
&lt;span class=&quot;token-function&quot;&gt;log&lt;/span&gt;(&lt;span class=&quot;token-string&quot;&gt;&amp;quot;Done.&amp;quot;&lt;/span&gt;)
&lt;span class=&quot;token-keyword&quot;&gt;return&lt;/span&gt; log.&lt;span class=&quot;token-function&quot;&gt;snapshot&lt;/span&gt;()
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This gives you the best of both worlds: maximum I/O performance from concurrent execution, with the reliability of deterministic, source-order assembly.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;5.-%E2%9E%A1%EF%B8%8F-sequential-by-exception&quot; tabindex=&quot;-1&quot;&gt;5. ➡️ Sequential by Exception&lt;/h2&gt;
&lt;p&gt;Of course, sometimes you absolutely need things to happen in a specific order - especially when calling external functions with side effects, like writing to a database or making stateful API calls.&lt;/p&gt;
&lt;p&gt;For these cases, Cascada provides a small set of surgical tools. Each one sequences only what it touches, leaving the rest of the script free to run concurrently.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The &lt;code&gt;!&lt;/code&gt; marker&lt;/strong&gt; - signals that an external call has side effects on a path. The path must be on the context object, not a local variable. Once any call on a path is marked with &lt;code&gt;!&lt;/code&gt;, all subsequent accesses on that path wait - method calls (whether or not they carry &lt;code&gt;!&lt;/code&gt;) and property reads alike - while unrelated operations continue concurrently. Sequencing is also hierarchical: marking &lt;code&gt;bank!&lt;/code&gt; sequences not just &lt;code&gt;bank&lt;/code&gt; itself but all sub-paths such as &lt;code&gt;bank.account&lt;/code&gt; and &lt;code&gt;bank.user&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token-comment&quot;&gt;// `bank.account` is provided by the render context.&lt;/span&gt;
bank.account!.&lt;span class=&quot;token-function&quot;&gt;deposit&lt;/span&gt;(&lt;span class=&quot;token-number&quot;&gt;100&lt;/span&gt;)
bank.account.&lt;span class=&quot;token-function&quot;&gt;getStatus&lt;/span&gt;()    &lt;span class=&quot;token-comment&quot;&gt;// waits - plain calls on a sequential path wait too&lt;/span&gt;
bank.account!.&lt;span class=&quot;token-function&quot;&gt;withdraw&lt;/span&gt;(&lt;span class=&quot;token-number&quot;&gt;50&lt;/span&gt;)  &lt;span class=&quot;token-comment&quot;&gt;// waits - as do further ! calls&lt;/span&gt;

&lt;span class=&quot;token-comment&quot;&gt;// Meanwhile, these run concurrently with everything above&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; preferences = &lt;span class=&quot;token-function&quot;&gt;getUserPreferences&lt;/span&gt;()
&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; analytics = &lt;span class=&quot;token-function&quot;&gt;fetchAnalytics&lt;/span&gt;()
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If many calls go through the same ordered interface, &lt;code&gt;sequence&lt;/code&gt; gives that path a local name and applies the same idea without repeating &lt;code&gt;!&lt;/code&gt; on every line:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;sequence db = services.db
&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; user = db.&lt;span class=&quot;token-function&quot;&gt;getUser&lt;/span&gt;(&lt;span class=&quot;token-number&quot;&gt;1&lt;/span&gt;)
&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; state = db.connectionState
db.&lt;span class=&quot;token-function&quot;&gt;updateLastSeen&lt;/span&gt;(user.id)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Think of &lt;code&gt;sequence&lt;/code&gt; as syntactic sugar for &amp;quot;this external object should be used sequentially here.&amp;quot; It is not a channel; it does not build output or get materialized with &lt;code&gt;.snapshot()&lt;/code&gt;. It is a named ordered interface around an external context object, useful when the object itself is the thing that needs strict source-code ordering.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The &lt;code&gt;each&lt;/code&gt; loop&lt;/strong&gt; - iterates one item at a time. Use it when per-iteration side effects must not overlap.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token-keyword&quot;&gt;each&lt;/span&gt; id &lt;span class=&quot;token-keyword&quot;&gt;in&lt;/span&gt; idsToWrite
  db!.&lt;span class=&quot;token-function&quot;&gt;write&lt;/span&gt;(id)   &lt;span class=&quot;token-comment&quot;&gt;// each write completes before the next starts&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;endeach&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It&#39;s concurrent by default, sequential by exception - the opposite of traditional programming. You only pay for ordering where you actually need it.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;6.-%E2%98%A3%EF%B8%8F-errors-flow-like-data&quot; tabindex=&quot;-1&quot;&gt;6. ☣️ Errors Flow Like Data&lt;/h2&gt;
&lt;p&gt;Traditional &lt;code&gt;try/catch&lt;/code&gt; blocks don&#39;t work well in a massively concurrent system. If one of fifty concurrent API calls fails, should everything stop?&lt;/p&gt;
&lt;p&gt;Cascada uses a more resilient model called dataflow poisoning. When an operation fails, it doesn&#39;t throw an exception; it produces an &lt;code&gt;Error Value&lt;/code&gt;. This error then &amp;quot;poisons&amp;quot; any other variable or operation that depends on it. Crucially, unrelated operations continue running completely unaffected.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token-comment&quot;&gt;// Three concurrent calls - fetchPosts() fails, the others succeed&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; user = &lt;span class=&quot;token-function&quot;&gt;fetchUser&lt;/span&gt;(&lt;span class=&quot;token-number&quot;&gt;123&lt;/span&gt;)         &lt;span class=&quot;token-comment&quot;&gt;// ✅ Succeeds&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; posts = &lt;span class=&quot;token-function&quot;&gt;fetchPosts&lt;/span&gt;(&lt;span class=&quot;token-number&quot;&gt;123&lt;/span&gt;)       &lt;span class=&quot;token-comment&quot;&gt;// ❌ Fails and becomes an Error Value&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; comments = &lt;span class=&quot;token-function&quot;&gt;fetchComments&lt;/span&gt;(&lt;span class=&quot;token-number&quot;&gt;123&lt;/span&gt;) &lt;span class=&quot;token-comment&quot;&gt;// ✅ Succeeds&lt;/span&gt;

&lt;span class=&quot;token-comment&quot;&gt;// Now, let&amp;#39;s see what happens:&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; userName = user.name           &lt;span class=&quot;token-comment&quot;&gt;// ✅ Works fine, uses the successful result&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; commentCount = comments.length &lt;span class=&quot;token-comment&quot;&gt;// ✅ Works fine - unrelated to posts&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; postCount = posts.length       &lt;span class=&quot;token-comment&quot;&gt;// ❌ Becomes an error because &amp;#39;posts&amp;#39; is poisoned&lt;/span&gt;

&lt;span class=&quot;token-comment&quot;&gt;// Detect with `is error` and provide fallbacks&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;if&lt;/span&gt; posts &lt;span class=&quot;token-keyword&quot;&gt;is&lt;/span&gt; &lt;span class=&quot;token-keyword&quot;&gt;error&lt;/span&gt;
  posts = []           &lt;span class=&quot;token-comment&quot;&gt;// Assign a default&lt;/span&gt;
  postCount = &lt;span class=&quot;token-number&quot;&gt;0&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;endif&lt;/span&gt;

&lt;span class=&quot;token-keyword&quot;&gt;return&lt;/span&gt; {
  userName: userName,
  postCount: postCount,
  commentCount: commentCount
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Poisoning extends to control flow, too. If the condition of an &lt;code&gt;if&lt;/code&gt; or &lt;code&gt;switch&lt;/code&gt; is an Error Value, neither branch runs - and any variable that &lt;em&gt;would have been&lt;/em&gt; modified in either branch becomes poisoned. The same applies to loops: a poisoned iterable poisons everything the loop body would have touched.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; role = &lt;span class=&quot;token-string&quot;&gt;&amp;quot;guest&amp;quot;&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; user = &lt;span class=&quot;token-function&quot;&gt;fetchUser&lt;/span&gt;(&lt;span class=&quot;token-number&quot;&gt;123&lt;/span&gt;)  &lt;span class=&quot;token-comment&quot;&gt;// ❌ Fails&lt;/span&gt;

&lt;span class=&quot;token-comment&quot;&gt;// `user.isAdmin` is poisoned, so neither branch executes&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;if&lt;/span&gt; user.isAdmin
  role = &lt;span class=&quot;token-string&quot;&gt;&amp;quot;admin&amp;quot;&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;else&lt;/span&gt;
  role = &lt;span class=&quot;token-string&quot;&gt;&amp;quot;member&amp;quot;&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;endif&lt;/span&gt;

&lt;span class=&quot;token-comment&quot;&gt;// `role` is now poisoned - both branches would have written to it,&lt;/span&gt;
&lt;span class=&quot;token-comment&quot;&gt;// so the engine can&amp;#39;t safely leave it as &amp;quot;guest&amp;quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This ensures corrupted state can&#39;t silently slip past as a stale default value. If something would have been touched, it carries the failure forward.&lt;/p&gt;
&lt;p&gt;You can also peek inside an Error Value using the &lt;code&gt;#&lt;/code&gt; operator to inspect its details - message, source, and more - without triggering further propagation:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token-keyword&quot;&gt;if&lt;/span&gt; posts &lt;span class=&quot;token-keyword&quot;&gt;is&lt;/span&gt; &lt;span class=&quot;token-keyword&quot;&gt;error&lt;/span&gt;
  &lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; msg = posts#message
  &lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; origin = posts#source.origin
&lt;span class=&quot;token-keyword&quot;&gt;endif&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This approach isolates failures, prevents corrupted data from producing incorrect results, and makes your workflows incredibly robust. The beauty of dataflow poisoning is that you have complete control over recovery: detect errors anywhere with &lt;code&gt;is error&lt;/code&gt;, repair them with fallbacks, log them for monitoring, or retry - all while the rest of your script continues executing normally.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;7.-%F0%9F%9B%A1%EF%B8%8F-transactional-recovery-with-guard&quot; tabindex=&quot;-1&quot;&gt;7. 🛡️ Transactional Recovery with &lt;code&gt;guard&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;For higher-stakes operations - like database writes that span multiple steps - a single fallback isn&#39;t enough. You need to roll back. The &lt;code&gt;guard&lt;/code&gt; block is Cascada&#39;s transactional recovery primitive: it acts like a save point. If anything inside fails, the channel writes and sequential paths from before the guard are automatically restored.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token-keyword&quot;&gt;data&lt;/span&gt; out

guard
  out.status = &lt;span class=&quot;token-string&quot;&gt;&amp;quot;processing&amp;quot;&lt;/span&gt;

  db!.&lt;span class=&quot;token-function&quot;&gt;beginTransaction&lt;/span&gt;()
  db!.&lt;span class=&quot;token-function&quot;&gt;insert&lt;/span&gt;(user)
  db!.&lt;span class=&quot;token-function&quot;&gt;update&lt;/span&gt;(account)   &lt;span class=&quot;token-comment&quot;&gt;// ❌ Suppose this fails&lt;/span&gt;
  db!.&lt;span class=&quot;token-function&quot;&gt;commit&lt;/span&gt;()
  out.status = &lt;span class=&quot;token-string&quot;&gt;&amp;quot;success&amp;quot;&lt;/span&gt;

recover err
  &lt;span class=&quot;token-comment&quot;&gt;// STATE RESTORED automatically:&lt;/span&gt;
  &lt;span class=&quot;token-comment&quot;&gt;//  - data writes inside the guard are reverted&lt;/span&gt;
  &lt;span class=&quot;token-comment&quot;&gt;//  - the db! sequential path is repaired and safe to use again&lt;/span&gt;
  db!.&lt;span class=&quot;token-function&quot;&gt;rollback&lt;/span&gt;()
  out.&lt;span class=&quot;token-keyword&quot;&gt;error&lt;/span&gt; = &lt;span class=&quot;token-string&quot;&gt;&amp;quot;Transaction failed: &amp;quot;&lt;/span&gt; + err#message
endguard

&lt;span class=&quot;token-keyword&quot;&gt;return&lt;/span&gt; out.&lt;span class=&quot;token-function&quot;&gt;snapshot&lt;/span&gt;()
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;By default, &lt;code&gt;guard&lt;/code&gt; protects all channels and sequential paths in scope. The &lt;code&gt;recover&lt;/code&gt; block runs only if the guarded code finished in an error state, with the cleanup state already in place. It&#39;s like a database transaction - except for your entire workflow.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;8.-%F0%9F%92%A1-familiar-syntax&quot; tabindex=&quot;-1&quot;&gt;8. 💡 Familiar Syntax&lt;/h2&gt;
&lt;p&gt;Cascada offers a clean, expressive syntax that will feel instantly familiar if you know JavaScript. Variables, conditionals, loops, and reusable functions all work the way you&#39;d expect.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Syntax&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Variables&lt;/td&gt;
&lt;td&gt;&lt;code&gt;var name = value&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Conditionals&lt;/td&gt;
&lt;td&gt;&lt;code&gt;if / elif / else / endif&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Switch&lt;/td&gt;
&lt;td&gt;&lt;code&gt;switch / case / default / endswitch&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Logic operators&lt;/td&gt;
&lt;td&gt;&lt;code&gt;and&lt;/code&gt;, &lt;code&gt;or&lt;/code&gt;, &lt;code&gt;not&lt;/code&gt; (Python-style)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Concurrent loop&lt;/td&gt;
&lt;td&gt;&lt;code&gt;for item in array&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sequential loop&lt;/td&gt;
&lt;td&gt;&lt;code&gt;each item in array&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;While loop&lt;/td&gt;
&lt;td&gt;&lt;code&gt;while condition / endwhile&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Inline &lt;code&gt;if&lt;/code&gt; (ternary)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;a if condition else b&lt;/code&gt; (Python-style)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Functions&lt;/td&gt;
&lt;td&gt;&lt;code&gt;function name(x, y=&amp;quot;default&amp;quot;) ... endfunction&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Filters&lt;/td&gt;
&lt;td&gt;&lt;code&gt;value | filterName(args)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Imports&lt;/td&gt;
&lt;td&gt;&lt;code&gt;import &amp;quot;file&amp;quot; as ns&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Comments&lt;/td&gt;
&lt;td&gt;&lt;code&gt;// line&lt;/code&gt;, &lt;code&gt;/* block */&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token-comment&quot;&gt;// Variables, conditionals, loops&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; discount = &lt;span class=&quot;token-number&quot;&gt;0&lt;/span&gt;

&lt;span class=&quot;token-keyword&quot;&gt;if&lt;/span&gt; userType == &lt;span class=&quot;token-string&quot;&gt;&amp;quot;premium&amp;quot;&lt;/span&gt;
  discount = &lt;span class=&quot;token-number&quot;&gt;0.10&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;endif&lt;/span&gt;

&lt;span class=&quot;token-comment&quot;&gt;// Reusable functions with default and keyword arguments&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token-function&quot;&gt;formatPrice&lt;/span&gt;(amount, discount=&lt;span class=&quot;token-number&quot;&gt;0&lt;/span&gt;)
  &lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; final = amount * (&lt;span class=&quot;token-number&quot;&gt;1&lt;/span&gt; - discount)
  &lt;span class=&quot;token-keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token-string&quot;&gt;&amp;quot;$&amp;quot;&lt;/span&gt; + final
&lt;span class=&quot;token-keyword&quot;&gt;endfunction&lt;/span&gt;

&lt;span class=&quot;token-keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token-function&quot;&gt;formatPrice&lt;/span&gt;(&lt;span class=&quot;token-number&quot;&gt;100&lt;/span&gt;, discount)  &lt;span class=&quot;token-comment&quot;&gt;// &amp;quot;$90&amp;quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You get variables (&lt;code&gt;var&lt;/code&gt;), conditionals (&lt;code&gt;if/elif/else&lt;/code&gt;), concurrent (&lt;code&gt;for&lt;/code&gt;) and sequential (&lt;code&gt;each&lt;/code&gt;, &lt;code&gt;while&lt;/code&gt;) loops, reusable &lt;code&gt;function&lt;/code&gt; definitions, and modular code organization through &lt;code&gt;import&lt;/code&gt; and &lt;code&gt;extends&lt;/code&gt;.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;%F0%9F%9A%80-putting-it-all-together&quot; tabindex=&quot;-1&quot;&gt;🚀 Putting It All Together&lt;/h2&gt;
&lt;p&gt;Cascada is &lt;code&gt;a work in progress&lt;/code&gt; under active development and evolving quickly. Install it with:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;npm install cascada-engine
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here&#39;s a realistic example: a customer dashboard endpoint that aggregates data from three APIs, enriches each order, recovers from missing recommendations, and logs the access - all from a single Cascada script.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;JavaScript context:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token-keyword&quot;&gt;import&lt;/span&gt; { AsyncEnvironment } &lt;span class=&quot;token-keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token-string&quot;&gt;&amp;#39;cascada-engine&amp;#39;&lt;/span&gt;;

&lt;span class=&quot;token-keyword&quot;&gt;const&lt;/span&gt; env = &lt;span class=&quot;token-keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token-function&quot;&gt;AsyncEnvironment&lt;/span&gt;();

&lt;span class=&quot;token-keyword&quot;&gt;const&lt;/span&gt; context = {
  userId: &lt;span class=&quot;token-number&quot;&gt;42&lt;/span&gt;,

  &lt;span class=&quot;token-comment&quot;&gt;// Three independent data sources&lt;/span&gt;
  fetchUser:            (id) =&amp;gt; api.&lt;span class=&quot;token-function&quot;&gt;get&lt;/span&gt;(&lt;span class=&quot;token-string&quot;&gt;`/users/${id}`&lt;/span&gt;),
  fetchOrders:          (id) =&amp;gt; api.&lt;span class=&quot;token-function&quot;&gt;get&lt;/span&gt;(&lt;span class=&quot;token-string&quot;&gt;`/users/${id}/orders`&lt;/span&gt;),
  fetchRecommendations: (id) =&amp;gt; recommender.&lt;span class=&quot;token-function&quot;&gt;suggestFor&lt;/span&gt;(id),

  &lt;span class=&quot;token-comment&quot;&gt;// Per-order enrichment - runs concurrently for each order&lt;/span&gt;
  enrichOrder: (order) =&amp;gt; api.&lt;span class=&quot;token-function&quot;&gt;get&lt;/span&gt;(&lt;span class=&quot;token-string&quot;&gt;`/orders/${order.id}/details`&lt;/span&gt;),

  &lt;span class=&quot;token-comment&quot;&gt;// Stateful service for audit logging&lt;/span&gt;
  audit: auditLogger,
};

&lt;span class=&quot;token-keyword&quot;&gt;const&lt;/span&gt; dashboard = &lt;span class=&quot;token-keyword&quot;&gt;await&lt;/span&gt; env.&lt;span class=&quot;token-function&quot;&gt;renderScriptString&lt;/span&gt;(script, context);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Cascada script:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token-comment&quot;&gt;// Three sources fetched concurrently&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; user = &lt;span class=&quot;token-function&quot;&gt;fetchUser&lt;/span&gt;(userId)
&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; orders = &lt;span class=&quot;token-function&quot;&gt;fetchOrders&lt;/span&gt;(userId)
&lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; recs = &lt;span class=&quot;token-function&quot;&gt;fetchRecommendations&lt;/span&gt;(userId)

&lt;span class=&quot;token-keyword&quot;&gt;data&lt;/span&gt; report

&lt;span class=&quot;token-comment&quot;&gt;// Cascada waits for `user` to resolve, then writes both properties&lt;/span&gt;
report.user.name = user.name
report.user.tier = &lt;span class=&quot;token-string&quot;&gt;&amp;quot;premium&amp;quot;&lt;/span&gt; &lt;span class=&quot;token-keyword&quot;&gt;if&lt;/span&gt; user.lifetimeValue &amp;gt; &lt;span class=&quot;token-number&quot;&gt;1000&lt;/span&gt; &lt;span class=&quot;token-keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token-string&quot;&gt;&amp;quot;standard&amp;quot;&lt;/span&gt;

&lt;span class=&quot;token-comment&quot;&gt;// Each order is enriched concurrently - but the final array is in source order&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;for&lt;/span&gt; order &lt;span class=&quot;token-keyword&quot;&gt;in&lt;/span&gt; orders
  &lt;span class=&quot;token-keyword&quot;&gt;var&lt;/span&gt; details = &lt;span class=&quot;token-function&quot;&gt;enrichOrder&lt;/span&gt;(order)
  report.orders.&lt;span class=&quot;token-function&quot;&gt;push&lt;/span&gt;({
    id: order.id,
    total: details.total,
    status: details.status
  })
&lt;span class=&quot;token-keyword&quot;&gt;endfor&lt;/span&gt;

&lt;span class=&quot;token-comment&quot;&gt;// Recommendations are nice-to-have - recover with an empty list if they fail&lt;/span&gt;
&lt;span class=&quot;token-keyword&quot;&gt;if&lt;/span&gt; recs &lt;span class=&quot;token-keyword&quot;&gt;is&lt;/span&gt; &lt;span class=&quot;token-keyword&quot;&gt;error&lt;/span&gt;
  recs = []
&lt;span class=&quot;token-keyword&quot;&gt;endif&lt;/span&gt;
report.recommendations = recs

&lt;span class=&quot;token-comment&quot;&gt;// Audit the access - `!` keeps log calls sequential&lt;/span&gt;
&lt;span class=&quot;token-comment&quot;&gt;// without slowing anything else down&lt;/span&gt;
audit!.&lt;span class=&quot;token-function&quot;&gt;log&lt;/span&gt;(&lt;span class=&quot;token-string&quot;&gt;&amp;quot;dashboard_viewed&amp;quot;&lt;/span&gt;, userId)

&lt;span class=&quot;token-keyword&quot;&gt;return&lt;/span&gt; report.&lt;span class=&quot;token-function&quot;&gt;snapshot&lt;/span&gt;()
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In one short script you&#39;ve got three concurrent API calls, a concurrent enrichment loop with deterministic ordering, error recovery for non-critical data, and a sequential side effect - without &lt;code&gt;Promise.all&lt;/code&gt;, &lt;code&gt;await&lt;/code&gt;, or a single race condition to reason about.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;⚠️ Heads up!&lt;/strong&gt; Cascada is a new project. You might run into bugs, and the documentation is catching up with the code. Your feedback and contributions are welcome as we build the future of asynchronous programming.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;%F0%9F%8E%AF-why-this-matters&quot; tabindex=&quot;-1&quot;&gt;🎯 Why This Matters&lt;/h2&gt;
&lt;p&gt;Cascada isn&#39;t trying to replace JavaScript - it&#39;s designed to be the backbone of your data layer.&lt;/p&gt;
&lt;p&gt;Use it to compose complex workflows that wire together LLMs, APIs, databases, and external services. By inverting the traditional programming model - concurrent by default, sequential by exception - it lets you build high-performance data pipelines that are surprisingly simple and intuitive, all with maximum I/O throughput and minimum mental overhead.&lt;/p&gt;
&lt;p&gt;The result? Code that reads like synchronous logic but executes with the performance of carefully orchestrated async operations. You get to focus on &lt;em&gt;what&lt;/em&gt; you&#39;re building instead of &lt;em&gt;how&lt;/em&gt; to manage promises, race conditions, and execution order.&lt;/p&gt;
&lt;p&gt;And the best part? When you look at your Cascada script six months later, you&#39;ll actually understand what it does.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;final-thoughts&quot; tabindex=&quot;-1&quot;&gt;Final Thoughts&lt;/h2&gt;
&lt;p&gt;If you&#39;ve ever fought through promise hell, callback pyramids, or race conditions, Cascada might just feel like magic.&lt;/p&gt;
&lt;p&gt;It turns async programming from a juggling act into a walk in the park. You write code like a human - simple, sequential, intuitive - and let the runtime handle the concurrency and safety behind the scenes.&lt;/p&gt;
&lt;p&gt;The future of async programming isn&#39;t about getting better at promises. It&#39;s about not having to think about them at all.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Everything Everywhere All at Once</title>
    <link href="https://cascada.dev/posts/everything-everywhere-all-at-once/"/>
    <id>https://cascada.dev/posts/everything-everywhere-all-at-once/</id>
    <updated>2026-04-29T00:00:00Z</updated>
    <summary>Introducing CascadaScript: a programming language where everything runs concurrently by default, and operations only wait when they depend on another result.</summary>
    <content type="html">&lt;p&gt;What if there was a programming language with ordinary, instantly familiar syntax, where everything runs at once, concurrently - every statement, every part of every expression, every step inside every function call, every iteration of every loop, every task in every imported script - and an operation only waits when it actually depends on another&#39;s result?&lt;/p&gt;
&lt;p&gt;I am building exactly this in my &lt;a href=&quot;https://github.com/geleto/cascada&quot;&gt;project&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://cascada.dev/cascada-script/&quot;&gt;CascadaScript&lt;/a&gt; inverts the traditional model: concurrent by default, sequential by exception. And the most extraordinary thing about it is how ordinary its syntax is - instantly familiar to any JavaScript or Python developer. No special async syntax, no &lt;code&gt;await&lt;/code&gt;, no &lt;code&gt;Promise.all&lt;/code&gt;, no race conditions. Just write your logic. The runtime figures out what can run concurrently from data dependencies alone.&lt;/p&gt;
&lt;p&gt;Despite everything running out of order under the hood - all your arrays, objects, and output come out correctly ordered. Always. The final result is identical to sequential execution, just dramatically faster.&lt;/p&gt;
&lt;p&gt;It integrates into TypeScript/JavaScript applications and is particularly well suited for AI and LLM orchestration, data pipelines, ETL workflows, and high-throughput I/O coordination. I&#39;ve also been building &lt;a href=&quot;https://github.com/geleto/casai&quot;&gt;Casai&lt;/a&gt; - an AI orchestration library on top of it.&lt;/p&gt;
&lt;p&gt;If you&#39;re curious:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://cascada.dev/posts/cascada-script-intro/&quot;&gt;CascadaScript Introduction&lt;/a&gt; - the technical introduction article for developers&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cascada.dev/posts/cascada-kitchen-chef/&quot;&gt;The Kitchen Chef&#39;s Guide to Taming Chaos&lt;/a&gt; - the intuitive, no-jargon explanation that everyone can understand&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://cascada.dev/cascada-script/&quot;&gt;CascadaScript Specification&lt;/a&gt; - the full language reference&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/geleto/cascada&quot;&gt;Cascada GitHub Repository&lt;/a&gt; - open source · &lt;code&gt;npm install cascada-engine&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Feedback very welcome - it&#39;s early and it&#39;s real.&lt;/p&gt;
&lt;p&gt;Think Sequential. Run Concurrently.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>The Kitchen Chef&#39;s Guide to Taming Chaos</title>
    <link href="https://cascada.dev/posts/cascada-kitchen-chef/"/>
    <id>https://cascada.dev/posts/cascada-kitchen-chef/</id>
    <updated>2025-10-19T00:00:00Z</updated>
    <summary>Imagine writing code that automatically runs everything in parallel, with zero boilerplate, while making race conditions impossible. CascadaScript inverts traditional programming: it&#39;s parallel by default and sequential by exception. This post explains how it works using a high-end restaurant kitchen as an analogy.</summary>
    <content type="html">&lt;p&gt;The empty stares I get when I try to explain what Cascada is to non-technical people… well, let&#39;s just say I&#39;ve learned to recognize the precise moment someone mentally taps out, and I don&#39;t blame them.&lt;/p&gt;
&lt;p&gt;So this article is my attempt to explain Cascada in a simple, friendly way - no jargon, no tech-speak, just something intuitive and fun to read.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://cascada.dev/images/posts/kitchen-chef.png&quot; alt=&quot;A restaurant kitchen illustrating how Cascada coordinates concurrent work&quot; /&gt;&lt;/p&gt;
&lt;p&gt;If you can handle the technical version without mentally checking out, here&#39;s the full deep-dive: 👉 &lt;a href=&quot;https://cascada.dev/posts/cascada-script-intro/&quot;&gt;Introduction to CascadaScript&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The &lt;a href=&quot;https://cascada.dev/cascada-script/&quot;&gt;Cascada language&lt;/a&gt; helps applications coordinate lots of interconnected tasks, automatically running independent work at the same time.&lt;/p&gt;
&lt;p&gt;Modern software isn&#39;t just doing one thing at a time anymore - it might clean up raw data, split it into multiple chunks for parallel processing, send each chunk to an AI to extract insights, use the results to create summaries, and then generate a polished final deliverable - all while, at the same time, sending real-time alerts to users and updating dashboards. Run all of that step-by-step, and suddenly you&#39;re waiting minutes instead of seconds.. With Cascada You write simple, in-order, sequential logic, and it automatically runs independent tasks in parallel while guaranteeing every step happens exactly when its input data is ready.&lt;/p&gt;
&lt;p&gt;Most people understand cooking better than concurrency, so why not explain Cascada using cooks, ingredients, and a world-class restaurant kitchen that keeps everything running in harmony?&lt;/p&gt;
&lt;p&gt;Aprons on - let&#39;s step into a kitchen during dinner rush and see how this works...&lt;/p&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;the-problem%3A-the-overwhelmed-chef&quot; tabindex=&quot;-1&quot;&gt;The Problem: The Overwhelmed Chef&lt;/h2&gt;
&lt;img src=&quot;https://cascada.dev/images/posts/chef.png&quot; alt=&quot;Overwhelmed chef in a busy kitchen&quot; style=&quot;float: left; margin-right: 20px; margin-bottom: 10px; max-width: 200px; border-radius: 8px;&quot; /&gt;
&lt;p&gt;Imagine a kitchen with a talented Head Chef working alone. He&#39;s skilled, but he does only one thing at a time - and it&#39;s painfully slow. And it gets worse... modern kitchens (and modern applications) aren&#39;t preparing single meals - they&#39;re handling dozens of simultaneous orders.&lt;/p&gt;
&lt;p&gt;He is receiving shipments, checking multiple suppliers, cooking  - all while trying to get food out fast.&lt;/p&gt;
&lt;p&gt;It&#39;s a mental nightmare. What you really need is a system that can handle massive parallelism while automatically understanding what must wait for what.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;the-naive-fix%3A-hire-more-cooks&quot; tabindex=&quot;-1&quot;&gt;The Naive Fix: Hire More Cooks&lt;/h2&gt;
&lt;p&gt;So the Chef tries the obvious solution: hire more cooks and divide the work.&lt;/p&gt;
&lt;p&gt;An order arrives for a full five-course banquet for twelve guests. The chef assigns each course to a different cook: &amp;quot;Everyone start now - we need this done at the same time!&amp;quot; All five cooks rush to begin simultaneously. It should be beautifully parallel.&lt;/p&gt;
&lt;p&gt;Except:&lt;/p&gt;
&lt;p&gt;The truffle oil hasn&#39;t arrived yet, but Cook A is already frantically searching for it to start the risotto. Cook B fires up twelve steaks at once - three medium-rare, six medium, three well-done. The first few finish perfectly seared, then sit... cooling on the counter, losing their heat and their magic... while he waits for the last well-done steaks to catch up. And because everyone started at the exact same moment, all five cooks need the oven at precisely 6:15pm.&lt;/p&gt;
&lt;p&gt;They stand there, waiting their turn. The oven becomes a bottleneck.&lt;/p&gt;
&lt;p&gt;Meanwhile, the salad cook finishes in 8 minutes but sits idle for the next 30 while waiting for the entrées. The dessert cook started making soufflés immediately... which collapse by the time the main course is finally ready.&lt;/p&gt;
&lt;p&gt;The problem? Dividing the work seems parallel, but it ignores reality - what the kitchen needs isn&#39;t just dividing work among cooks - it needs intelligent orchestration that starts each task exactly when its ingredients are ready and naturally spreads all available work.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;the-solution%3A-the-cascada-kitchen-manager&quot; tabindex=&quot;-1&quot;&gt;The Solution: The Cascada Kitchen Manager&lt;/h2&gt;
&lt;img src=&quot;https://cascada.dev/images/posts/robot.png&quot; alt=&quot;Hard-working robot manager in a busy kitchen&quot; style=&quot;float: left; margin-right: 20px; margin-bottom: 10px; max-width: 200px; border-radius: 8px;&quot; /&gt;
&lt;p&gt;Now, imagine a completely different kitchen. Here, the Head Chef&#39;s job is not to manage, but to design.&lt;/p&gt;
&lt;p&gt;He sits down in a quiet office and writes out the entire, complex banquet recipe. And here is the most crucial part: he writes it just as he always has, in a simple, sequential, top-to-bottom list of steps. It looks and feels like any other recipe he&#39;s ever written.&lt;/p&gt;
&lt;p&gt;But this simple-looking recipe is incredibly powerful because it&#39;s a smart, adaptable plan. The Chef can include rules, choices, and logic as part of his normal, sequential writing:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&amp;quot;If the season is Winter, use the root vegetables. Otherwise, use the summer squash.&amp;quot;&lt;/li&gt;
&lt;li&gt;&amp;quot;For each of the 12 dinner orders for the main party, prepare one beef medallion to the customer&#39;s requested temperature.&amp;quot;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The recipe isn&#39;t a rigid checklist - it&#39;s a flexible blueprint that responds to real-world conditions.&lt;/p&gt;
&lt;p&gt;Once this smart, yet familiar-looking recipe is written, his main job is done. He hands it to a brilliant Kitchen Manager (that&#39;s &lt;a href=&quot;https://cascada.dev/cascada-script/&quot;&gt;Cascada&lt;/a&gt;) and can go relax.&lt;/p&gt;
&lt;p&gt;The Manager doesn&#39;t just read a fixed list. He interprets this smart recipe in real-time, as things are happening. He checks the calendar, sees the 12 orders, understands the client&#39;s needs, and then executes the Chef&#39;s simple, sequential logic with maximum parallelism, handling all the complexity himself.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;understanding-ingredient-dependencies&quot; tabindex=&quot;-1&quot;&gt;Understanding Ingredient Dependencies&lt;/h2&gt;
&lt;img src=&quot;https://cascada.dev/images/posts/dependencies.png&quot; alt=&quot;Ingredient dependencies chart&quot; style=&quot;float: left; margin-right: 20px; margin-bottom: 10px; max-width: 200px; border-radius: 8px;&quot; /&gt;
&lt;p&gt;The Kitchen Manager is smart enough to handle dependencies within this dynamic logic automatically. Imagine the recipe calls for a final pan sauce, which requires three things: the pan the beef was seared in, some sautéed shallots, and the reduced red wine.&lt;/p&gt;
&lt;p&gt;He orchestrates a multi-part ballet:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;He has Assistant D searing the beef.&lt;/li&gt;
&lt;li&gt;Simultaneously, he has Assistant E sautéing shallots.&lt;/li&gt;
&lt;li&gt;And at the same time, Assistant F is reducing the wine.&lt;/li&gt;
&lt;li&gt;He then tells a final assistant, Assistant G: &amp;quot;Stand by. You cannot start your job until the beef is done, the shallots are ready, AND the wine is reduced. The moment all three are finished - no matter the timing - you will combine them to create the final sauce.&amp;quot;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;While Assistant G is waiting for these multiple inputs, the rest of the kitchen is not waiting with him! Other dishes are being prepped, other sauces are being reduced. This automatic waiting - without blocking anything else - is the fundamental principle that makes the system so efficient.&lt;/p&gt;
&lt;p&gt;The Chef never wrote &amp;quot;wait for the beef&amp;quot; or &amp;quot;check if the shallots are ready.&amp;quot; He just wrote the recipe in order. The Manager figured out the dependencies automatically.&lt;/p&gt;
&lt;p&gt;And here&#39;s the quiet magic: even though dishes are prepped in wildly unpredictable order - sauces finishing before proteins, garnishes before mains - every plate that leaves the kitchen comes out exactly as the Chef wrote it. From the dining room, it looks as if one unhurried chef had cooked the whole banquet alone.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;when-order-matters-(!)&quot; tabindex=&quot;-1&quot;&gt;When Order Matters (!)&lt;/h2&gt;
&lt;p&gt;In our kitchen, dozens of things happen at once - rice simmering, sauces reducing, plates going out.
But sometimes, one particular part of a dish must follow a very specific sequence.
That&#39;s what the &lt;code&gt;!&lt;/code&gt; mark is for.&lt;/p&gt;
&lt;p&gt;It tells the Kitchen Manager:
&amp;quot;For this dish or this component, follow these steps in order - no reordering, no overlap - while everything else runs freely in parallel.&amp;quot;&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Risotto! Toast the rice in olive oil until translucent.&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Risotto! Add a ladle of stock and stir until absorbed.&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Risotto! Repeat until the rice is just al dente.&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;(Meanwhile, other cooks are grilling steaks, prepping salads, and making desserts...)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Risotto.sauce! Reduce the white wine base.&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Risotto.sauce! Whisk in butter, then finish with grated parmesan.&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Risotto! Combine the sauce and rice, season, and plate.&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Whenever the Manager sees a &lt;code&gt;!&lt;/code&gt; on risotto, they assign one cook to perform those risotto steps in the exact written order.
When they see &lt;code&gt;risotto.sauce!&lt;/code&gt;, another cook handles those sauce steps sequentially - only the sauce follows that order, not the entire dish.&lt;/p&gt;
&lt;p&gt;Think of &lt;code&gt;Risotto!&lt;/code&gt; and &lt;code&gt;Risotto.sauce!&lt;/code&gt; as two separate assembly lines - each runs its own steps in order, but the two lines operate independently and in parallel with each other. Everything else in the kitchen continues running independently as well.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;!&lt;/code&gt; doesn&#39;t make the kitchen slower - it simply ensures that for that component, each step happens exactly in sequence, while the rest of the kitchen stays fully concurrent.&lt;/p&gt;
&lt;p&gt;The final combining step automatically waits for both the rice sequence and the sauce sequence to complete - that&#39;s the Manager&#39;s automatic dependency tracking at work.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;(And if the recipe ever went deeper, say &lt;code&gt;risotto.sauce.topping!&lt;/code&gt;, the same idea would apply - each level keeps its own internal order without blocking anything else.)&lt;/em&gt;&lt;/p&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;the-domino-effect%3A-handling-kitchen-disasters&quot; tabindex=&quot;-1&quot;&gt;The Domino Effect: Handling Kitchen Disasters&lt;/h2&gt;
&lt;p&gt;A perfect recipe assumes a perfect kitchen, but in reality, things go wrong. An oven breaks. A key ingredient is missing. An assistant calls in sick.&lt;/p&gt;
&lt;p&gt;Traditional kitchens panic - the whole operation can grind to a halt. But the &lt;a href=&quot;https://cascada.dev/cascada-script/&quot;&gt;Cascada&lt;/a&gt; Manager handles disasters with what&#39;s called &lt;code&gt;error propagation&lt;/code&gt; - a controlled ripple effect that contains problems without stopping the entire kitchen.&lt;/p&gt;
&lt;p&gt;Imagine someone discovers the truffles that arrived this morning are actually expired and can&#39;t be used. The Manager immediately marks Truffles as &amp;quot;contaminated&amp;quot; - or in &lt;a href=&quot;https://cascada.dev/cascada-script/&quot;&gt;Cascada&lt;/a&gt; terms, &amp;quot;poisoned&amp;quot; (we use this word figuratively to describe how one bad piece of data makes everything depending on it unusable too). This contamination then flows through the dependency chain: the Truffle Risotto, which needs those truffles, automatically becomes &amp;quot;unavailable&amp;quot; as well.&lt;/p&gt;
&lt;p&gt;Crucially, the assistants making the steak and salad are unaffected. They never needed truffles, so they continue working at full speed. The problem is perfectly contained.&lt;/p&gt;
&lt;h3 id=&quot;three-ways-to-handle-disasters&quot; tabindex=&quot;-1&quot;&gt;Three Ways to Handle Disasters&lt;/h3&gt;
&lt;p&gt;The Head Chef has powerful options for dealing with unavailable items:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1. Intervene Immediately:&lt;/strong&gt; The moment the truffles become unavailable, a contingency plan can trigger automatically: &lt;em&gt;&amp;quot;Send an assistant to the specialty market to buy more!&amp;quot;&lt;/em&gt; If they succeed, the problem is solved and the risotto is back on track. This is perfect for retrying failed operations.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2. Substitute Gracefully:&lt;/strong&gt; The recipe itself can have a backup plan built in: &lt;em&gt;&amp;quot;If fresh truffles are unavailable, use high-quality mushroom duxelles instead.&amp;quot;&lt;/em&gt; The Manager sees this, makes the substitution, and the problem is stopped before it spreads.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3. Check and Adapt Later:&lt;/strong&gt; You can also do nothing immediately. The risotto simply remains &amp;quot;unavailable.&amp;quot; Later, you can check its status and decide how to proceed. Maybe you offer the customer an alternative dish. Or perhaps the truffles finally arrive from a backup supplier - in which case you can restart the risotto preparation with the fresh ingredients. The choice of if, when and how to handle the problem is always yours.&lt;/p&gt;
&lt;p&gt;The beauty is that unavailability doesn&#39;t cause crashes or confusion - it&#39;s just information that flows through the system, letting you respond at the right moment.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;the-takeaway%3A-effortless-parallelism&quot; tabindex=&quot;-1&quot;&gt;The Takeaway: Effortless Parallelism&lt;/h2&gt;
&lt;p&gt;You write as if every step were a single, simple action. Yet beneath the surface, the system runs a perfectly choreographed symphony of parallel work.&lt;/p&gt;
&lt;p&gt;That&#39;s the quiet power of being &lt;em&gt;implicitly parallel by design.&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;learn-more-and-try-it-yourself&quot; tabindex=&quot;-1&quot;&gt;Learn More and Try It Yourself&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://cascada.dev/posts/cascada-script-intro/&quot;&gt;CascadaScript Introduction&lt;/a&gt; - A more technical introduction to CascadaScript&#39;s syntax, features, and how it solves real async programming challenges&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://cascada.dev/cascada-script/&quot;&gt;CascadaScript Documentation&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/geleto/cascada&quot;&gt;Cascada GitHub Repository&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/geleto/casai&quot;&gt;Casai&lt;/a&gt; - an AI orchestration library built on Cascada for effortless, parallel agent and workflow design.&lt;/p&gt;
&lt;p&gt;⚡ &lt;strong&gt;Try it now:&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;npm install cascada-engine
&lt;/code&gt;&lt;/pre&gt;
&lt;hr /&gt;
</content>
  </entry>
  
</feed>
