UNPKG

1.3 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.promisify = void 0;
4var util_1 = require("util");
5Object.defineProperty(exports, "promisify", { enumerable: true, get: function () { return util_1.promisify; } });
6// /**
7// * Transforms callback-based function -- func(arg1, arg2 .. argN, callback) -- into an ES6-compatible Promise.
8// * Promisify provides a default callback of the form (error, result) and rejects when `error` is not null. You can also
9// * supply thisArg object as the second argument which will be passed to `apply`.
10// */
11// // HACK: This can't be properly typed without variadic kinds https://github.com/Microsoft/TypeScript/issues/5453
12// export function promisify<T>(originalFn: (...args: any[]) => void, thisArg?: any): (...callArgs: any[]) => Promise<T> {
13// const promisifiedFunction = async (...callArgs: any[]): Promise<T> => {
14// return new Promise<T>((resolve, reject) => {
15// const callback = (err: Error | null, data?: T) => {
16// err === null || err === undefined ? resolve(data) : reject(err);
17// };
18// originalFn.apply(thisArg, [...callArgs, callback]);
19// });
20// };
21// return promisifiedFunction;
22// }
23//# sourceMappingURL=promisify.js.map
\No newline at end of file