villa
Version:
Promise utilities for async/await-ready environment.
39 lines • 985 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Call a Node.js-style asynchronous function and return a correspondent
* promise.
*/
function call(fn, ...args) {
return new Promise((resolve, reject) => {
fn.call(undefined, ...args, (error, value) => {
if (error) {
reject(error);
}
else {
resolve(value);
}
});
});
}
exports.call = call;
/**
* Wrap a Node.js-style asynchronous function to a function that returns
* promise.
*/
function async(fn) {
return function (...args) {
return new Promise((resolve, reject) => {
fn.call(this, ...args, (error, value) => {
if (error) {
reject(error);
}
else {
resolve(value);
}
});
});
};
}
exports.async = async;
//# sourceMappingURL=function.js.map