Metreeca Gear
    Preparing search index...

    Function bind

    • Binds an implementation to a service.

      The implementation may be asynchronous, so that a facility whose construction depends on a value only another service can supply, such as a client keyed from a secret vault, is still resolved by a synchronous lookup: bound implementations are constructed and awaited as the execution opens, under the terms detailed at Executor.

      Important

      An implementation is held to the same all-or-nothing requirement as any other factory, and an asynchronous one is the most exposed to it: whatever it awaits may be awaited again from scratch, as the run that started it may be abandoned before it records an instance.

      Type Parameters

      • T extends {} | null

        The type of the bound service

      Parameters

      • service: Service<T>

        The service to be bound

      • factory: NoInfer<() => Awaitable<T>>

        The implementation to be used in its place, awaited before the job runs where it is asynchronous

      Returns Binding<T>

      An immutable binding pairing service with factory

      bind(createClient, async () => new Client(await service(createVault)("api.key")));