Closed rvenugopal closed 6 years ago
For anyone else who might be interested, here is a function which can help promisify this library.
function promisifyAll(input) {
function promisifier(method) {
return function promisified(...args) {
return new Promise((resolve) => {
args.push(resolve);
const self = this;
method.apply(self, args);
});
};
}
function promisifyAll(obj) {
for (const key in obj) {
if (typeof obj[key] === 'function' && key.indexOf('Async') === -1) {
obj[key + 'Async'] = promisifier(obj[key])
}
}
}
promisifyAll(input);
return input
}
const bittrexPromisified = promisifyAll(require('node.bittrex.api'));
bittrexPromisified.getmarketsummariesAsync()
.then((data) => {
console.log('Results:', data.result.length)
})
There is an option for this already. See inverse_callback_arguments
I would like to use
const bittrex = blueBird.promisifyAll(require('node.bittrex.api'));
However, as the library does not follow standard node convention, I am not able to.A work around I am using to promisify individual methods on ad-hoc basis using the below method but is not ideal (i am using