Cotal TypeScript packages
    Preparing search index...

    Class SimHandler

    An effect method that throws settles its journal entry failed, and a resume replays that failure without calling the handler again, no matter how healthy the handler is on the next attempt. For work that is in flight, call EffectContext.bind with the facts that identify it before awaiting the external result, and leave the entry pending if the host is interrupted there: a resume then calls the handler with those facts in EffectContext.resume so it can reattach rather than issue a second action. A bind followed by a throw is still a throw: the entry settles failed with the external attached, and a resume replays it, so report what happened rather than throwing it, the way applyCheckpointPolicy does for an expiry. Throw EffectRefused when the host has no substrate for the step at all, so a resume performs it live instead of replaying a failure for work that never happened.

    Implements

    Index
    script: SimScript = {}
    • Advance virtual time immediately. The timed effects go through the event queue instead.

      Parameters

      • ms: number

      Returns void

    • The one effect with a reply contract. The request's schema is read as the shorthand (askSchemaShape), and every scripted reply is checked against it: a non-conforming reply consumes one attempt, one scripted occurrence, and one reply's worth of virtual time, and running out of attempts reports L4006, exactly as a production handler must. An unreadable schema is refused (L4022) rather than skipped, because a schema the handler cannot read and silently ignores is a contract the program believes in and nobody checks. To exercise the exhaustion path, script at least as many replies as attempts: the simulator still never invents one, so a script that runs out first fails as L6001.

      Parameters

      Returns Promise<unknown>

    • The host clock, which the interpreter uses to stamp startedAt and endedAt on journal entries. Production reads the wall clock; simulation reads a virtual one, which is how a program that waits four hours is tested in microseconds without pretending the wait did not happen. The program's own now() never reads this: it reads the run clock derived from those journalled stamps, which is what makes time advance only at effect boundaries.

      Returns number

    • waitUntil's cadence, on the virtual clock.

      NOTHING IS SCRIPTED HERE, and that is the correct shape rather than a gap. The OBSERVATION is the program's own probe, which the interpreter calls; this handler owns only the waiting. So there is no answer to invent and therefore nothing for the "an unscripted effect is an error" rule to protect: the simulator cannot green-light a broken program by guessing, because it is not being asked for a value at all.

      The cadence parks on the same event queue every other timed effect uses, so a wait that polls hourly for a day is simulated in microseconds while the run clock still moves a day. The deadline is compared on the virtual clock AFTER the park, so a cadence that steps over the deadline reports it rather than observing once more past it.

      Parameters

      Returns Promise<boolean>

    • Every effect the run performed, in order, for the dry-run report.

      Returns readonly Consumption[]

    • Script entries the run never reached. Usually a renamed step, which is worth saying out loud: a script that silently stops matching is a test that silently stops testing.

      Returns readonly string[]

    • Across a thread boundary the delivered branch's continuation runs in the other realm, so draining this realm's microtasks no longer means it has reached its next park. The host that owns the boundary says when it has, and the pump waits for that before each delivery (#2240).

      Parameters

      • settled: () => Promise<void>

      Returns () => void