Cotal TypeScript packages
    Preparing search index...

    Interface EffectHandler

    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.

    interface EffectHandler {
        ask(req: AskRequest, ctx: EffectContext): Promise<unknown>;
        checkpoint(
            req: CheckpointRequest,
            ctx: EffectContext,
        ): Promise<CheckpointRaw>;
        closeConclave(req: ConclaveRequest, ctx: EffectContext): Promise<null>;
        monitor(req: MonitorRequest, ctx: EffectContext): Promise<null>;
        notify(req: NotifyRequest, ctx: EffectContext): Promise<null>;
        now(): number;
        observe(req: ObserveRequest, ctx: EffectContext): Promise<boolean>;
        openConclave(
            req: ConclaveRequest,
            ctx: EffectContext,
        ): Promise<ChannelHandleValue>;
        participant(
            req: ParticipantRequest,
            ctx: EffectContext,
        ): Promise<AgentHandleValue>;
        sleep(req: SleepRequest, ctx: EffectContext): Promise<null>;
        spawn(req: SpawnRequest, ctx: EffectContext): Promise<AgentHandleValue>;
        turn(req: TurnRequest, ctx: EffectContext): Promise<TurnResultValue>;
        useQuiescence?(settled: () => Promise<void>): () => void;
        wait(req: WaitRequest, ctx: EffectContext): Promise<unknown>;
    }

    Implemented by

    Index
    • 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

    • Hold the run until it is time to observe again, and say whether there was time.

      true means "observe now"; false means the deadline passed while waiting, and the interpreter raises the catchable L4023. The handler never evaluates the predicate and never sees the observation: the probe is the program's, the interpreter calls it, and this is only the durable pause between two calls. A handler with no durable timer may implement it with whatever it has — the simulator parks on its virtual clock — and one that cannot wait durably at all should refuse with EffectRefused rather than busy-wait, exactly as any other effect it has no substrate for.

      Parameters

      Returns Promise<boolean>

    • Optional. A host that runs the program in another realm (the worker bridge) calls this once with a function that resolves when the program has reacted to everything the handler has answered so far. A handler that schedules its own deliveries, as the simulator does, awaits it before each one; any other handler can leave it out. It returns a release the host calls when that realm is gone, or never started, after which the handler paces itself again. A handler that wraps another forwards it.

      Parameters

      • settled: () => Promise<void>

      Returns () => void