I am receiving batches of live data from an Apache Kafka message queue every second, and for each batch I need to run a database query within my app. It is crucial for all the queries from the previous batch to be made before the next batch of data is processed. However, the order of execution of the queries per batch do not matter. Due to async, this is much harder.
batchOfRows.on('message', function (data) {
for (var i = 0; i < batchOfRows.rows.length; i++) {
query(batchOfRows.rows[i])
.then(result => console.log(result))
.catch(error => console.log(error));
}
});
This is giving me unexpected behavior. NOTE: These batches of data are sent every second, forever, so the promises must resolve before the next batch is received dynamically