# EffectGate

`interface` in `seedcord` · v0.14.0

<https://docs.seedcord.org/packages/seedcord/0.14.0/interfaces/effect-gate>

A gate that carries a side effect, split so the effect fires only once the gate is the one that let the request through. `check` peeks and refuses, `commit` applies the effect after the whole gate set passes. [`Cooldown`](/packages/seedcord/0.14.0/functions/cooldown) is the catalog gate that returns one. Build one with [`defineEffectGate`](/packages/seedcord/0.14.0/functions/define-effect-gate).

```ts
interface EffectGate<
    Ctx extends GateContextBase = GateContext,
    Name extends string = string
> extends Gate<Ctx, Name>
```

## Examples

```ts
// a factory returning a typed effect gate
function MyEffectGate(): EffectGate<GateContextBase, 'MyEffectGate'> {
    return defineEffectGate(
        'MyEffectGate',
        (ctx) => {
            if (shouldRefuse(ctx)) throw new MyNotice();
        },
        (ctx) => {
            applyMyEffect(ctx);
        }
    );
}
```

## Properties

### [GateBrand]

```ts
readonly [GateBrand]: true
```

Phantom brand that marks a real gate, you never set or read it.

### name

```ts
readonly name: Name
```

The gate's name, surfaced in a mismatch error and joined by the combinators.

## Methods

### check

```ts
async check(ctx: Ctx): Promise<void>
```

Reads the context and refuses by throwing a Notice or a Silence, or passes by resolving.

### commit

```ts
async commit(ctx: Ctx): Promise<void>
```

Applies the side effect, run only after the whole gate set passes.

## See also

- [defineEffectGate](/packages/seedcord/0.14.0/functions/define-effect-gate)
