1👍
you can use promise to resolve the above issue.
billing = billingService(user_id).then(results => {
//Here in the results variable the output of billing service method will be stored if billing service method returns a promise.
recommendation = recommendation_service(user_id)})
Promise is the most efficient way to address asynchronous calls in javascript.
If you are specifically searcing for any library you can use ‘q’ library of node.js
0👍
You can try to use ES7’s async/await. It’ll be easier to write and your code will look a lot cleaner too.
Once you get it to work, your code will look something like:
const billing = await billingService(user_id)
const recommendation = await recommendation_service(user_id)
I’d recommend learning Promises too (afterall they’ve been successfully saving people from callback hell) to unmistify async/await (as your billingService and recommendation_service would eventually need to be async functions before they can be awaited)
Hope this helps!
Source:stackexchange.com