Helper to lazy update a promise and an associated value.

 import { LazyValue } from "apprt-core/promise-utils";

const lazy = new LazyValue();

// code which needs the value, has to use:
const theValue = await lazy.promise;

// code which like to update the value uses:
lazy.value = "newValue";

// the value can updated several times.
// with every update the promise is replaced

// this resets the value to not fulfilled
// the promise will then block again.
lazy.value = undefined;

// NOTE: currently the promise can not be switched into an error state.

Type Parameters

  • T

Accessors

Accessors

  • get promise(): Promise<T>
  • The promise which will resolve.

    Returns Promise<T>