Send Pipeline
Source file: packages/core/src/journey-machine/send.ts
This file turns an incoming event into either:
- a committed transition
- a committed navigation fallback
- a terminal status change
- or a non-transitioning result with optional error information
How It Works
Section titled “How It Works”executeSend(...)starts by checking that the machine is still"running"and emitstransition.start. If the runtime has already been disposed, the surrounding queue resolves a non-transitioning result withJourneyDisposedErrorinstead of throwing.handleHeadlessSend(...)short-circuits omitted-transition definitions:goToStepByIdvalidates the target step and commits a direct step transitiongoToNextStepand custom events resolve as no-ops- terminal events and
goToPreviousStepstill continue through the normal pipeline
resolveTransitionsForSend(...)then handles the graph/lineargoToStepByIdspecial case by filtering to only matching declaredgoToStepByIdtransitions for the requested target step.selectTransitionForSend(...)callsselectTransition(...)fromhelpers.ts. While async guards are running, it updatessnapshot.asyncthrough the async-state controller and passes a run-scopedAbortSignalinto the guard args.- If transition selection throws or times out, the file records step error state, emits
transition.error, and resolves the send result witherrorinstead of rejecting. - If no transition matches,
handleNoTransitionMatch(...)applies the built-in fallbacks:goToPreviousStepfalls back to history navigationgoToNextStepcan auto-complete the journey whenrequireExplicitCompletionis not set and no explicit next-step transition was declared- everything else becomes a non-transitioning result
- If a transition matched,
resolveNextContext(...)runs its synchronousupdateContextcallback, applies timeout protection to async guard work, and returns the next context or an error result. - When the async work is done, the file clears the source step’s async loading state, resolves the target, and
delegates the actual snapshot commit to navigation:
- terminal targets go through
commitTerminalTransition(...) - step targets go through
commitStepTransition(...)
- terminal targets go through
What This File Does Not Do
Section titled “What This File Does Not Do”- It does not own the queue. That belongs to Runtime Queue.
- It does not build the committed snapshot shape. That belongs to Navigation Commits and Helpers.
- It does not store async state itself. That belongs to Async State.
This separation is what keeps transition selection, snapshot commits, and async bookkeeping independently readable.
Recommended Reading
Section titled “Recommended Reading”- Read Helpers for
selectTransition(...), abort/timeout handling, and target resolution. - Read Navigation Commits for the snapshot writes this file delegates to.
- Read Core API Overview and Transitions Syntax for the public version of this behavior.
- Read Core Async Behavior for the user-facing semantics of guard and context-update errors.