What is a Mutex and when to use it?
masterA Mutex (mutual exclusion) is a primitive used to synchronize asynchronous operations in JavaScript. While JavaScript is single-threaded, the asynchronous execution model allows for race conditions (e.g., when multiple async calls attempt to access or modify the same state during different event loop turns).
Locking a mutex returns a promise that resolves once the mutex becomes available. Once the protected async process is complete, the lock must be released to allow the next scheduled task to execute.