UNPKG

729 BTypeScriptView Raw
1/**
2 * @name promisify
3 * @summary Wraps an async callback into a `Promise`
4 * @description
5 * Wraps the supplied async function `fn` that has a standard JS callback `(error: Error, result: any)` into a `Promise`, passing the supplied parameters. When `error` is set, the Promise is rejected, else the Promise resolves with the `result` value.
6 * @example
7 * <BR>
8 *
9 * ```javascript
10 * const { promisify } from '@polkadot/util';
11 *
12 * await promisify(null, ((a, cb) => cb(null, a), true); // resolves with `true`
13 * await promisify(null, (cb) => cb(new Error('error!'))); // rejects with `error!`
14 * ```
15 */
16export declare function promisify<R = any>(self: unknown, fn: (...params: any[]) => any, ...params: any[]): Promise<R>;