I'm trying to wait on two promises and get both functions to be called. Below is my AWS Lambda, but I believe this is purely a Node problem.
In my log, I see @@BP12.1, and BP1-1, amd BP1-2, but I don't see BP1-3, BP1-4, and BP1-5. I can't see evidence that it called the static MessageSession.getAccessToken token. I'd like the code below to call both sendMessage and updateStatus, both of which return promises, and wait for the completion of them. I'd like sendMessage to actually call the getAccessToken and create the message.
I have a Promise to return something which joins two promises. What did I do wrong with the Promise nesting?
exports.handler = async(event, context, callback) => {
...
console.info('@@BP12.1: ');
var statusTypeName = 'AVAILABLE';
(async() => {
await Promise.all([sendMessage(event), updateStatus(event, statusTypeName).promise]);
})();
...
}
async function sendMessage(payload) {
const promise = new Promise(function(resolve, reject) {
console.info('@@BP1-1');
let argumentParserResult = { ...};
console.info('@@BP1-2');
let accessToken = MessagingSession.getAccessToken(argumentParserResult).then((accessTokenResponse) => {
console.info('@@BP3');
argumentParserResult.accessToken = accessTokenResponse.access_token;
let messagingSession = new MessagingSession(MessagingSession.getInitializedSolaceModule(), argumentParserResult);
console.info('@@BP4');
resolve(messagingSession);
}).catch(error => {
console.info('@@BP5');
console.info("Error fetching access token: " + error);
reject(error);
})
});
return promise;
}