Here is my code:
for (var i = 0; i < items.length; i++) {
doSomeWork('Company","{message : "message"}');
}
doSomeWork = function (companyIdentifier,item) {
var serialisedMessage = new serialisedMessageWithMetadata(item);
//I want this to block until the callback inside send is fired.
send(companyIdentifier, serialisedMessage.getJSON());
}
send = function (queueId, msg) {
var sqsQueueUrl = this.createQueueUrl(queueId);
var sqsParams = {
MessageBody: JSON.stringify(msg),
QueueUrl: sqsQueueUrl
};
sqs.sendMessage(sqsParams, function (err, data) {
if (err) {
console.log('ERR', err);
}
else {
console.log(data);
}
});
}
I want my for loop to wait on the callback in sendMessage being fired. Looking through some articles on Google, I started to think Promises is what I needed, but this seems really complicated way of simply block a function (and I couldn't get the examples working either!)
I suspect it's something basic I missing, and was hoping for something like "await".
Any help would be appreciated.