method IFeatureFlags.isEnabledAsync
Since 0.2.0
IFeatureFlags.isEnabledAsync(
flag: string,
context?: FlagContext
): Promise<boolean>

Evaluates a flag, awaiting the backing provider when it can produce a more accurate answer asynchronously.

Optional, and additive: a provider with a purely local snapshot (config, memory, database polling) has nothing to await, so its implementation simply resolves IFeatureFlags.isEnabled. The method exists for providers whose SDK evaluates asynchronously — LaunchDarkly's server SDK being the motivating case — where the synchronous path must answer from a cached snapshot and therefore returns a configured fallback the first time it sees a given context.

Prefer this method wherever a wrong answer on a cold context would matter (billing, entitlement, an irreversible action); prefer IFeatureFlags.isEnabled on hot paths that cannot await.

Examples

Example 1

const flags = ctx.services.get<IFeatureFlags>(CAPABILITIES.FEATURE_FLAGS);
const on = await flags.isEnabledAsync?.('new-billing', { userId: user.id });

Parameters

flag: string

Flag name

optional
context: FlagContext

Targeting context

Return Type

Promise<boolean>

true when the flag is on for this context; unknown flags evaluate to false

Usage

import { type IFeatureFlags } from "common/src/index.ts";