UPDATE
I just realized something fundamentally wrong with this approach, and that nested callbacks cannot return something to their parent callback. I came to the end of the JS world and came from an era Promisesand did not know that this is a problem with callbacks. But I have not seen enough examples for Meteor using promises, so I used callbacks instead. However, if this code can be improved, I would really appreciate it.
Question
So, I call the method from the client using:
Meteor.call('cart.useProfileAddress', {}, (error, address) => {
console.info('Address', address) // this returns undefined on client
})
This is the method in my api/carts/cartsMethod.js
export const useProfileAddress = new ValidatedMethod({
name: 'cart.useProfileAddress',
validate(args) {
},
run(args) {
const person = Persons.findOne({'userId': Meteor.userId()});
getClosestStore.call({address: person.address}, (error, result) => {
updateCartAddress.call({address: person.address}, (error, result) => {
if (!error) {
console.info('Returning Address', person.address)
return person.address
}
})
})
}
})
What could be the problem with the code above? Maybe because I'm trying to get the value from a nested callback?
- , ? , Node, promises, Meteor ( 1.4). .