Function deferredApi

  • Creates an async api that can be invoked immediately but where the underlying api can be resolved at a later time.

    This allows you to defer the initialization of an api until it is an appropriate time to do so, for example, until certain parameters or services are available that this api requires.

    Upon invokation of any method, it will first wait for the underlying api to be provided before proceeding.

    See suspended_api and unsuspended_api.

    Parameters

    • async_factory: any

    Returns any

    Example

    // SomeUiComponent.js

    const [fetch, resolve_fetch] = deferred_api();
    console.log(await fetch("https://example.com"));

    // we only want to fetch client-side
    on_component_mount_clientside(() => {
    resolve_fetch(window.fetch);
    });

Generated using TypeDoc