/** * Transports a promise which can be resolved or rejected using the given functions. * Created by {@link createManualPromise}. */ interface ManualPromise { /** * The promise which will resolve. */ promise: Promise; /** * Call this function to full fill the promise. * @param val the result */ resolve: (val: T) => void; /** * Rejects the promise. * @param e an error */ reject: (e: unknown) => void; } /** * @returns a ManualPromise which helps to separate a promise from the resolve/reject methods. * @example * ```ts * import { createManualPromise } from "apprt-core/promise-utils"; * * const manualPromise = createManualPromise(); * * // the created promise * const promise = manualPromise.promise; * * // can be resolved by * manualPromise.resolve("value"); * * // or rejected by * manualPromise.reject(new Error("error")); * * // destructuring is allowed * const {promise, resolve, reject} = createManualPromise(); * ``` */ declare function createManualPromise(): ManualPromise; /** * Helper to lazy update a promise and an associated value. * * @example * ```ts * 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. * ``` */ declare class LazyValue { #private; constructor(val?: T); /** * The promise which will resolve. */ get promise(): Promise; set value(val: T | undefined); get value(): T | undefined; } export { LazyValue, createManualPromise }; export type { ManualPromise };