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 #19

Closed
benjamingr opened this issue Jan 6, 2016 · 12 comments
Closed

Promises #19

benjamingr opened this issue Jan 6, 2016 · 12 comments

Comments

@benjamingr
Copy link

Given they're in the language standard now, it would probably be the better idea to use them or at least support them - especially since people want to use async/await or generator coroutines in new code.

@keithwhor
Copy link
Owner

Definitely considering what working with Promises would look like in Nodal, and appreciate the feedback. :)

@benjamingr
Copy link
Author

Well mostly,

  • controller methods can return promises (which are resolved and returned as json or rejected as errors).
  • API methods (orm for instance) return promises instead of taking callbacks.

@davej
Copy link

davej commented Jan 6, 2016

+1, particularly on the promise interface for the ORM. You can still expose the end method for backwards compatibility if desired.

@benjamingr
Copy link
Author

Or do like mongoose and return a promise if and only if no callback is passed

@chrisenytc
Copy link

👍

@erf
Copy link

erf commented Jan 22, 2016

+1 couldn't the controller routes be generator functions like in KOA ?

@keithwhor
Copy link
Owner

Closing right now; no intention to use promises in short-term future. Will re-approach in time.

@arcseldon
Copy link

+1 for promises support.

2 similar comments
@christophehurpeau
Copy link

+1 for promises support.

@tilap
Copy link

tilap commented Apr 1, 2016

+1 for promises support.

@ncksllvn
Copy link

I used Bluebird's promisifyAll as a quick way to add promise support.

models/overrides.js

  var Promise = require('bluebird')
  var Nodal = require('nodal')
  var Composer = require('nodal/core/required/composer')

  Promise.promisifyAll(Nodal.Model)
  Promise.promisifyAll(Nodal.Model.prototype)
  Promise.promisifyAll(Composer.prototype)

controllers/dogs_controller.js

show(){
    Dog.
        findAsync( this.params.route.id ).
        then(dog => this.respond(dog)).
        catch(err => this.respond(err))
}

Hope this helps!!

@sylvainlap
Copy link
Contributor

+1 for promises support.

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

10 participants