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

Promise interface #14

Open
silverwind opened this issue Jun 12, 2018 · 5 comments
Open

Promise interface #14

silverwind opened this issue Jun 12, 2018 · 5 comments

Comments

@silverwind
Copy link
Collaborator

Been working with a lot of async/await lately and a callback API is really hindering there. I think we can return promises if the callback argument is not a function. Or should we go the route of completely removing the callback interface and do a major version bump?

@mafintosh
Copy link
Owner

I'm too dependent on the interface in upstream deps to make a breaking change like removing the cbs so i'd very much prefer to keep that.

You can easily util.promisify this api as it is now right?

@silverwind
Copy link
Collaborator Author

I'm fine if you wanna go the non-breaking route and support both. util.promisify is of course an option, but it's not as "clean" if you know what I mean :)

@mafintosh
Copy link
Owner

What about adding promises.js that exports the functions with util.promisify? then it's less bloated and to use promises you just do require('dns-socket/promises') ?

@silverwind
Copy link
Collaborator Author

We can actually have both callbacks and promises when we test whether the last argument is a function. Or would this too brittle for your tastes?

@realhidden
Copy link
Contributor

If you only use the .query function, this one is a simple solution:

const socket = dnsSocket({...});
const qsocket = promisify(socket.query.bind(socket));

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

3 participants