Setu-TS
    Preparing search index...

    Interface IResilienceService

    Resilience service registered under CAPABILITIES.RESILIENCE.

    const resilience = ctx.services.get<IResilienceService>(CAPABILITIES.RESILIENCE);
    const guarded = resilience.wrap((signal) => fetch(url, { signal }), {
    circuitBreaker: true,
    retry: { limit: 3, delay: 100, backoff: 'exponential' },
    timeout: 2000,
    });
    const rates = await guarded();

    // A call that ignores the signal is still accepted, unchanged.
    const legacy = resilience.wrap(() => externalApi.fetchRates(), { timeout: 2000 });

    // The caller may also cancel from outside.
    const controller = new AbortController();
    const pending = guarded(controller.signal);
    controller.abort();

    0.1.0

    interface IResilienceService {
        wrap<T>(fn: ResilientCall<T>, options?: WrapOptions): HardenedCall<T>;
    }
    Index
    • Wraps fn with the selected patterns and returns a hardened callable that reuses one shared pattern chain across invocations, so circuit-breaker and bulkhead state persist across calls.

      Each attempt is handed an AbortSignal. The timeout layer aborts it with a TimeoutError when the deadline elapses, so a call that forwards the signal to its I/O is genuinely cancelled rather than left running in the background. An outer signal passed to the returned callable is linked into every layer: it stops the retry loop between attempts and rejects a call still queued behind the bulkhead.

      Type Parameters

      • T

        The protected call's result type

      Parameters

      • fn: ResilientCall<T>

        The protected call, handed the cancellation signal for the current attempt

      • Optionaloptions: WrapOptions

        Which patterns to apply and their policies

      Returns HardenedCall<T>

      A hardened callable accepting an optional caller-owned signal