I've been trying to avoid callback hell in Meteor but first, I'll explain my problem:
I have some Meteor methods declared in server, and I invoke them using Meteor.call in client, but the main problem is I have tons of callbacks making debugging a really difficult task to make (and manteinance too...). This wouldn't be an issue if I work with a "small" project, but I'm building a big one and I was planning on using promises but for my surprise... it's not working since Meteor.call only accepts callbacks.
I've read a lot of posts here and in Meteor forums and none of them can help me... is there any solution to this? (I tried deanius:promise package and it's still the same...)
Edit: using Meteor 1.4.2
You can use the bluebird
module for this. promisifyAll
lets you convert all functions on an object to use promises instead of callbacks, so instead of using Meteor.call
with a callback, you can use Meteor.callAsync
as a promise.
With callbacks:
Meteor.call(..., function(...) {
// ...
});
With promises:
Meteor.callAsync(...).then(function(...) {
// ...
});
http://bluebirdjs.com/docs/api/promise.promisifyall.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With