I am currently facing an issue. Correct me if i am wrong. In my project, I have a NodeJS server having mongoDB database & an android application connected to it.
There are 4 android devices connected to it and when server publishes the list, it send an emit call to all android devices via Socket.IO. The moment android receives emit call, it calls the API to get the published list. Here the request calls (4 requests) comes to server at same time.
And here what the unexpected assignment occurs to devices. Unexpected in the sense that there are some parameters based on which the allocation should be done to devices. When only one device is online then this scenario works perfectly but when concurrent requests arrives from more that one device then sometimes the concerned problem occurs.
Is it possible to handle concurrent request in one at a time way?
Discussions/suggestions are welcome. Execution flow is here
flowController.on('START', function () {
// Uploading and storing the binary data as excel file
});
flowController.on('1', function () {
// Validation to check if file contain required sheet with name and all and convert the file into JSON format
});
flowController.on('2', function () {
// Replacing the keys from the JSON to match the required keys
});
flowController.on('3', function () {
// Massive validation of records & seperating the records as per the activity
});
// Activity 1
flowController.on('4', function () {
// Insert records of Activity 1
});
// Activity 2
flowController.on('5', function () {
// Insert records of Activity 2
});
// Activity 3
flowController.on('6', function () {
// Insert records of Activity 3
});
// Activity 3
flowController.on('END', function () {
// End
});
io.emit('updatePublishedList', publishedList), and thensocket.on('updatePublishedList', function(publishedList) { /* do stuff here with list */ }4,5,6. If that is correct & based on what I am able to understand, I don't see any problem in the existing code flow.