Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Best practice for exposing promisifyable methods #840

Closed
dignifiedquire opened this issue Oct 31, 2015 · 1 comment
Closed

Best practice for exposing promisifyable methods #840

dignifiedquire opened this issue Oct 31, 2015 · 1 comment

Comments

@dignifiedquire
Copy link

I have a question on what's the best way for me to write an API that is compatible with promisifyAll.
At the moment it is written in this style

function API () {
  this.do = function (arg1, cb) {
    // do things
    cb(null, res)
  }
  this.nested.do = function (arg2, cb) {
    // do things
   cb(null, res)
  }
}

// usage
var api = new API()
api.do('hello', function (err, res) {...})
api.nested.do('world', function (err, res) {...})

Now this does not work with promisifyAll and I understand why (not using prototype, nested objects). But even if I change it to use API.prototype to assign the methods I still can't get the api.nested.do to be promisifed. Any ideas on how to solve this?

@petkaantonov
Copy link
Owner

You need to call promisifyAll on the nested object too. Also this issue tracker is only for bug reports or feature requests, questions about usage should be in stack overflow or the mailing list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants