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

Added asCallback/nodeify to the core #1376

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sadasant
Copy link

Hi everyone! 🐦 ⚡️

My team and I have been needing to use asCallback as a general utility, so I wonder if we could add asCallback/nodeify to the core functions?

Here's a simple PR with a simple test which passes ✅ 💚

Please let me know if anyone has any form of feedback \o/ and have a wonderful time.

@daedalus28
Copy link

daedalus28 commented Apr 25, 2017

In particular, this is useful for methods that don't use bluebird to promisify and only support callback style interfaces. With this, we can just pass promise returning (e.g. async) methods to things like these lifecycle hooks: http://sailsjs.com/documentation/concepts/models-and-orm/lifecycle-callbacks, e.g.

afterCreate: Promise.asCallback(async (val) => await something(val))

@benjamingr
Copy link
Collaborator

I'm currently discussing (last 2 days) on adding this to core: nodejs/CTC#109

Note that in bluebird this would be slow for async/await code since it's native (and not bluebird) promises.

@sadasant
Copy link
Author

One thing to note is that the current behavior of nodeify doesn't pass all the values sent to resolve to the callback function, at least that seems to be the case in the test I've been making.

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

Successfully merging this pull request may close these issues.

3 participants