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

Promises vs. callbacks #315

Open
pptp opened this issue Jan 8, 2017 · 2 comments
Open

Promises vs. callbacks #315

pptp opened this issue Jan 8, 2017 · 2 comments

Comments

@pptp
Copy link

pptp commented Jan 8, 2017

Hi!
You are using a passing of callback for supporting asynchrony

For example:

save(callback)

It means this callback will be called after saving.

I guess it will be more easier to use Promises for these purposes.
For example. We should type the following code:

Model.find(this.params.route.id, (err, model) => {
    this.respond(err || model);
});

So, using Promises we will be able to code as follows:

Model.find(this.params.route.id)
  .then(
    this.respond.bind(this),
    this.someErrorLogFunc.bind(this)
  )

As far as I know, Node supports Promises since the version 0.12. For earlier versions there are shims.

Are you going to use Promises in the Nodal in near future?

Thanks,
Mike

@eperiou
Copy link

eperiou commented Apr 10, 2017

Q, promises worked really well for the basic crud operations, except for query. The .end() function somehow gets in the way. And I had some issues when trying to nest promises, because the Model's need to be reconverted back to objets.

@gugadev
Copy link

gugadev commented May 4, 2017

+1 to @pptp. Async functions (aka async/await) is done and will come with the next ECMAScript release. So, I think we can benefit a lot if we use promises and async/await.

const obj = await Model.find({ ... });

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