Interface: TurnGate<T>
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 |
|---|---|---|
createdAt | readonly | DateTime |
id | readonly | string |
isSettled | readonly | boolean |
payload | readonly | unknown |
reason | readonly | string |
turnId | readonly | string |
Methods
_promise()
_promise(): Promise<T>;Internal
Returns the internal promise. Called by ctx.waitFor() to block the middleware pipeline.
Returns
Promise<T>
abort()
abort(): void;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;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;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.