I have a collection DATA, and a collection called SYNCS. Also a third collection that holds a FLAG.
Also, I have two functions, A function, will catch events on collection DATA, and write changes on SYNCS collection, to put them on a queue. if the FLAG is ON, it will ignore the events of DATA changes.
Function B executes every X time, it will first, put FLAG - ON, and then make the data changes that were saved until now on SYNCS. Then it will put FLAG - OFF.
Why to put FLAG - ON? Because, I want to ignore the events created by the changes made by function B.
The problem. The Function A (the one that is triggered by an event) always is executed after Function B finishes, so FLAG is OFF by that time.
So the events created during the function A, seems to be executed only after function B is finished.
Any suggestions on how to handle this, will be really appreciated.