Type Alias HedgingSettings<TParameters, TReturn, TContext>

HedgingSettings: HedgingCallbacks<TParameters, TContext> & ErrorPolicySettings<
    InferResultError<TReturn>,
> & {
    fallbacks: OneOrMore<
        Fallback<TParameters, TReturn>
        | NamedFallback<TParameters, TReturn>,
    >;
    middlewares?: AsyncMiddleware<TParameters, TReturn>[];
}

IMPORT_PATH: "@daiso-tech/core/async"

Type Parameters

Type declaration

  • fallbacks: OneOrMore<Fallback<TParameters, TReturn> | NamedFallback<TParameters, TReturn>>

    The fallback functions that run in case the primary function fails.

    import { retry } from "@daiso-tech/core/async";
    import { timeout } from "@daiso-tech/core/async";

    [timeout(), retry()]
  • Optionalmiddlewares?: AsyncMiddleware<TParameters, TReturn>[]

    Middlewares to apply on all fallback functions and on primary function.

    You can wrap primary and fallback functions with for example retry and timeout middlewares.

    import { retry, timeout, sequentialHedging } from "@daiso-tech/core/async";

    new AsyncHooks(fn, [
    sequentialHedging({
    fallbacks: [
    fn1,
    fn2,
    fn3,
    ],
    middlewares: [
    timeout({
    waitTime: TimeSpan.fromSeconds(2),
    }),
    retry({
    maxAttempts: 4
    }),
    ]
    })
    ], {
    signalBinder,
    })