How can I optimise the following (i.e. avoid nested promises)? It works but seems like I'm going to continue nesting promises
The code first authenticates and returns a service, then it feeds that service into a function that calls the api asynchronously to gets items, then I'll do something with the items after, probably calling another function containing an async call:
new Promise(function(resolve, reject) {
auth.authenticate(resolve);
}).then(function(service) {
console.log('service', service);
new Promise(function(resolve, reject) {
lineItems.getLineItems(service, resolve, reject);
}).then(function(items) {
console.log('returned line items');
console.log(items);
}).catch(function(err){
console.log('error!', err);
});
});