UNPKG

shelving

Version:

Toolkit for using data in JavaScript.

24 lines (23 loc) 1.63 kB
import type { Arguments } from "./function.js"; /** Callback function with no value. */ export type Callback = () => void; /** Callback function with no value and possibly returns a promise that must be handled. */ export type AsyncCallback = () => void | PromiseLike<void>; /** Callback function that receives a value. */ export type ValueCallback<T> = (value: T) => void; /** Callback function that receives a value and possibly returns a promise that must be handled. */ export type AsyncValueCallback<T = void> = (value: T) => void | PromiseLike<void>; /** Callback function that receives multiple values. */ export type ValuesCallback<T extends Arguments = []> = (...values: T) => void; /** Callback function that receives multiple values and possibly returns a promise that must be handled. */ export type AsyncValuesCallback<T extends Arguments = []> = (...values: T) => void | PromiseLike<void>; /** Callback function that receives an error. */ export type ErrorCallback = (reason: unknown) => void; /** Safely call a callback function (possibly with a value). */ export declare function call<A extends Arguments = []>(callback: (...v: A) => unknown, ...values: A): void; /** Return a callback function that safely calls a callback function (possibly with a value). */ export declare function called<A extends Arguments = []>(dispatcher: (...v: A) => unknown, ...values: A): Callback; /** Safely call a callback method (possibly wth a value). */ export declare function callMethod<A extends Arguments, M extends string | symbol>(obj: { [K in M]?: ((...v: A) => unknown) | undefined; }, key: M, ...values: A): void;