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 Parameter | Default type | Description |
|---|---|---|
T | unknown | The expected type of the resolution value. |
Properties
| Property | Modifier | Type | Description | Defined in |
|---|---|---|---|---|
createdAt | readonly | DateTime | When the gate was created. | src/lib/classes/turn_gate.ts:145 |
id | readonly | string | Unique identifier for this gate instance. | src/lib/classes/turn_gate.ts:137 |
isSettled | readonly | boolean | Whether the gate has been settled (resolved or rejected) and no longer blocks the turn. | src/lib/classes/turn_gate.ts:147 |
payload | readonly | unknown | Optional caller-supplied payload describing what the gate is waiting on. | src/lib/classes/turn_gate.ts:143 |
reason | readonly | string | Human-readable reason the gate was opened. | src/lib/classes/turn_gate.ts:141 |
turnId | readonly | string | Id of the turn this gate belongs to. | src/lib/classes/turn_gate.ts:139 |
Methods
abort()
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()
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
| Parameter | Type | Description |
|---|---|---|
error | Error | The rejection reason. |
Returns
void
Remarks
No-ops if the gate is already settled.
resolve()
resolve(value: unknown): void;Defined in: src/lib/classes/turn_gate.ts:274
Resolves the gate with value, unblocking the awaiting middleware.
Parameters
| Parameter | Type | Description |
|---|---|---|
value | unknown | The 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.