mcohen01 / node-quickbooks

nodejs client for Intuit's Quickbooks API
332 stars 235 forks source link

Return promises to allow async/await #109

Closed shaunc869 closed 6 years ago

shaunc869 commented 6 years ago

This is feature request, since Node 8 we can use the await/async pattern and it would be great if this library could be updated to return promises accordingly since pretty much everything is going this way already. Thanks for the consideration.

drewjs commented 6 years ago

As a temporary workaround you can use promisify to add "Async" versions of all the functions:

// core/Quickbooks.js
import QuickBooks from 'node-quickbooks';
import Promise from 'bluebird';

QuickBooks.setOauthVersion('2.0');

// Original functions must follow the `(err, value) =>` callback style
Promise.promisifyAll(QuickBooks.prototype);

// ...

export default QuickBooks;
// other/file.js
import Quickbooks from 'core/quickbooks';

const qb = new Quickbooks(/* opts */)

qb.getCompanyInfo(id, cb) // normal callback version
qb.getCompanyInfoAsync(id) // => Promise

I'm using bluebird's promisifyAll to add the additional functions to the prototype object. You could also use node 8's built in util.promisify to accomplish the same manually.

kyleabens commented 5 years ago

@drewjs Out of curiosity how could I use util.promisify? I'm having a hard time figuring this one out.

alex-osman commented 5 years ago

Why is this closed? This would be an extremely useful feature

ogrotten commented 2 years ago

@drewjs Out of curiosity how could I use util.promisify? I'm having a hard time figuring this one out.

Did you ever get the syntax for this? I'm struggling with this today 3 years later.

Thanks either way.

BrandonCopley commented 2 years ago

This is an important issue and wouldn't be hard to implement just using bluebird on this package thoughts?