obsidian-dev-utils
Version:
This is the collection of useful functions that you can use for your Obsidian plugin development
25 lines (24 loc) • 1.41 kB
text/typescript
/**
* @packageDocumentation
*
* Contains utility types and functions for handling value providers, which can be either direct values or functions that return values.
*/
import type { Promisable } from 'type-fest';
/**
* Value provider that can either be a direct value of type {@link Value} or a function that returns a value of type {@link Value}.
*
* @typeParam Value - The type of the value provided.
* @typeParam Args - The types of arguments passed to the function if the provider is a function.
*/
export type ValueProvider<Value, Args extends unknown[] = []> = ((abortSignal: AbortSignal, ...args: Args) => Promisable<Value>) | Value;
/**
* Resolves a value from a value provider, which can be either a direct value or a function that returns a value.
*
* @typeParam Args - The types of arguments passed to the function if the provider is a function.
* @typeParam Value - The type of the value provided.
* @param provider - The value provider to resolve.
* @param abortSignal - The abort signal to control the execution of the function.
* @param args - The arguments to pass to the function if the provider is a function.
* @returns A {@link Promise} that resolves with the value provided by the value provider.
*/
export declare function resolveValue<Value, Args extends unknown[]>(provider: ValueProvider<Value, Args>, abortSignal?: AbortSignal, ...args: Args): Promise<Value>;