Skip to content
Functioncorev0.10.0

defineEffectGate

Builds an EffectGate from a check and a commit. check peeks and refuses by throwing, and commit applies the side effect, running only once the whole gate set passes so a later refusal never commits. In an or, a refusing arm's queued commit is rolled back. This is how Cooldown peeks in check and charges the slot in commit.

See also:defineGate, the @Gated decorator from your transport package, Cooldown

defineEffectGate<Name, Ctx>(
    name: Name,
    check: (ctx: Ctx) => void | Promise<void>,
    commit: (ctx: Ctx) => void | Promise<void>
): EffectGate<Ctx, Name>

Name

The gate's literal name, used to name a mismatch error.

Name

The gate's literal name, used to name a mismatch error.

Ctx

The context both check and commit read, inferred from the ctx annotation.

Ctx

The context both check and commit read, inferred from the ctx annotation.

name

name: Name

The gate's name, used in mismatch errors.

check

check: (ctx: Ctx) => void | Promise<void>

Peeks and refuses by throwing, without applying the side effect.

commit

commit: (ctx: Ctx) => void | Promise<void>

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