Skip to content
2 min read · 479 words

Interface: TurnGate<T>

Defined in: src/lib/classes/turn_gate.ts:114

A cooperative suspension gate that blocks a turn's middleware pipeline until resolved, rejected, aborted, or timed out.

Remarks

Created exclusively via ctx.waitFor() — middleware never constructs a gate directly. The gate emits turnGateOpen on the runner's observability bus at creation time and turnGateClosed when it settles.

Resolution is validated against an optional schema before the internal promise is settled. A validation failure throws @nhtio/adk!E_INVALID_TURN_GATE_RESOLUTION synchronously in the caller's context — the promise is NOT settled and the gate remains open.

Type Parameters

Type ParameterDefault typeDescription
TunknownThe expected type of the resolution value.

Properties

PropertyModifierTypeDescriptionDefined in
createdAtreadonlyDateTimeWhen the gate was created.src/lib/classes/turn_gate.ts:145
idreadonlystringUnique identifier for this gate instance.src/lib/classes/turn_gate.ts:137
isSettledreadonlybooleanWhether the gate has been settled (resolved or rejected) and no longer blocks the turn.src/lib/classes/turn_gate.ts:147
payloadreadonlyunknownOptional caller-supplied payload describing what the gate is waiting on.src/lib/classes/turn_gate.ts:143
reasonreadonlystringHuman-readable reason the gate was opened.src/lib/classes/turn_gate.ts:141
turnIdreadonlystringId of the turn this gate belongs to.src/lib/classes/turn_gate.ts:139

Methods

abort()

ts
abort(): void;

Defined in: src/lib/classes/turn_gate.ts:311

Aborts the gate by firing the internal AbortController, which rejects the promise with @nhtio/adk!E_TURN_GATE_ABORTED.

Returns

void

Remarks

No-ops if the gate is already settled. Distinct from the turn-level abort signal — this allows callers to cancel a specific gate without aborting the whole turn.


reject()

ts
reject(error: Error): void;

Defined in: src/lib/classes/turn_gate.ts:297

Rejects the gate with error, unblocking the awaiting middleware with a rejection.

Parameters

ParameterTypeDescription
errorErrorThe rejection reason.

Returns

void

Remarks

No-ops if the gate is already settled.


resolve()

ts
resolve(value: unknown): void;

Defined in: src/lib/classes/turn_gate.ts:274

Resolves the gate with value, unblocking the awaiting middleware.

Parameters

ParameterTypeDescription
valueunknownThe resolution value. Must satisfy the gate's schema when one was provided.

Returns

void

Remarks

If a schema was provided at construction, value is validated synchronously before the promise is settled. A validation failure throws @nhtio/adk!E_INVALID_TURN_GATE_RESOLUTION in the caller's context — the promise is NOT settled and the gate remains open.

No-ops if the gate is already settled.

Throws

@nhtio/adk!E_INVALID_TURN_GATE_RESOLUTION when value fails schema validation.