---
url: >-
  https://canary.warp-drive.io/api/@warp-drive/utilities/handlers/classes/Gate.md
description: >-
  Request handler that wraps another handler and runs it only when a check
  function returns true for the request.
---

# &#x20;Gate

Defined in: [-private/handlers/gated.ts:17](https://github.com/warp-drive-data/warp-drive/blob/48dc0d277b98008082669dadc6a52e5c5682ef8e/warp-drive-packages/utilities/src/-private/handlers/gated.ts#L17)

## Implements

* `Handler`

## Constructors

### Constructor

```ts
new Gate(handler: Handler, checkFn: CheckFn): Gate;
```

Defined in: [-private/handlers/gated.ts:27](https://github.com/warp-drive-data/warp-drive/blob/48dc0d277b98008082669dadc6a52e5c5682ef8e/warp-drive-packages/utilities/src/-private/handlers/gated.ts#L27)

#### Parameters

##### handler

`Handler`

##### checkFn

`CheckFn`

#### Returns

`Gate`

## Methods

### request()

```ts
request<T = unknown>(context: RequestContext, next: NextFn<T>): 
  | Promise<T | StructuredDataDocument<T>>
| Future<T>;
```

Defined in: [-private/handlers/gated.ts:32](https://github.com/warp-drive-data/warp-drive/blob/48dc0d277b98008082669dadc6a52e5c5682ef8e/warp-drive-packages/utilities/src/-private/handlers/gated.ts#L32)

Method to implement to handle requests. Receives the request
context and a nextFn to call to pass-along the request to
other handlers.

#### Type Parameters

##### T

`T` = `unknown`

#### Parameters

##### context

`RequestContext`

##### next

`NextFn`<`T`>

#### Returns

| [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`T` | `StructuredDataDocument`<`T`>>
| `Future`<`T`>

#### Implementation of

```ts
Handler.request
```

## Properties

### checkFn

```ts
checkFn: CheckFn;
```

Defined in: [-private/handlers/gated.ts:25](https://github.com/warp-drive-data/warp-drive/blob/48dc0d277b98008082669dadc6a52e5c5682ef8e/warp-drive-packages/utilities/src/-private/handlers/gated.ts#L25)

The predicate used to decide whether [handler](#handler) should run for a given request.

***

### handler

```ts
handler: Handler;
```

Defined in: [-private/handlers/gated.ts:21](https://github.com/warp-drive-data/warp-drive/blob/48dc0d277b98008082669dadc6a52e5c5682ef8e/warp-drive-packages/utilities/src/-private/handlers/gated.ts#L21)

The wrapped handler to invoke when [checkFn](#checkfn) returns `true`.
