LoopBack should provide Promise-enabled API out of the box. The plan is to use the approach outlined in nodejs/node#173.
Tasks
Below is the original proposal from @coodoo.
I've been playing around with bluebird's promisifyAll() for a while, ended up I found it just take a couple of line to wrap the model and make it become async-compatible.
See code below:
varPromise=require("bluebird");module.exports=function(ResetKey){// once a model is attached to the data sourceResetKey.on('dataSourceAttached',function(obj){// wrap the whole model in Promise// but we need to avoid 'validate' method ResetKey=Promise.promisifyAll(ResetKey,{filter: function(name,func,target){return!(name=='validate');}});})}Once the model is wrapped, we can use Promise syntax instead of callbacks:
// old way - callbacksuser.save(function(err,result){...})// new way - promiseuser.saveAsync().then(function(result){...}).catch(function(err){...})Ain't that lovely? :)
Of course it would be even better if all those happened higher up in the chain and become default.
Thought?
LoopBack should provide Promise-enabled API out of the box. The plan is to use the approach outlined in nodejs/node#173.
Tasks
automigrate,autoupdate,discover*, etc.app.listen@promiseannotation Support @promise annotation strong-docs#63@promiseattributeBelow is the original proposal from @coodoo.
I've been playing around with bluebird's promisifyAll() for a while, ended up I found it just take a couple of line to wrap the model and make it become async-compatible.
See code below:
Once the model is wrapped, we can use Promise syntax instead of callbacks:
Ain't that lovely? :)
Of course it would be even better if all those happened higher up in the chain and become default.
Thought?