I have a data consistency problem, my afterSave trigger does many operations (a few database calls in a row) and I don’t want it to be interrupted by a call of afterSave from another record.
Sample:
I would like it to go like that:
- 1st record after save - gets something from DB
- 1st record after save - gets something from DB
3 )1st record after save - saves something to DB
— here I imaging some lock is unlocked and second after save can be called - 2nd record after save - gets something from DB
- 2nd record after save - gets something from DB
- 2nd record after save - saves something to DB
Sample of the wrong sequence
- 1st record after save - gets something from DB
- 2nd record after save - gets something from DB
3 )2nd record after save - gets something to DB - 2nd record after save - saves something from DB
- 1st record after save - gets something from DB
- 1st record after save - saves something to DB
I’m not very experienced in JS.
Is there any way like using semaphore that will stop going into AfterSave of specific Collection of 2 or more records at the same time? Simply: one call of AfterSave and then we can do another call of AfterSave.