Mutexes are stored globally reference by name, this is so you can obtain the
same lock from different contexts, including workers.
When a mutex is no longer required, the .finalize function should be called
to remove any internal references to it.
importmorticefrom'mortice'
constmutex = mortice()
// ...some time later
mutex.finalize()
Auto clean up
If your app generates a lot of short-lived mutexes and you want to clean them
up after the last lock has been released, pass the autoFinalize option to
mortice in the owning context:
importmorticefrom'mortice'
constmutex = mortice({ autoFinalize:true })
constrelease = awaitmutex.readLock() // ...some time later
release()
// mutex will be freed soon after
React native support
This module should run on react native but it only supports single-process
concurrency as it's not clear to the author (disclaimer - not a react native
dev) what the officially supported process concurrency model is.
Please open an issue if this is a feature you would like to see added.
Example
Clean up
Mutexes are stored globally reference by name, this is so you can obtain the same lock from different contexts, including workers.
When a mutex is no longer required, the
.finalize
function should be called to remove any internal references to it.Auto clean up
If your app generates a lot of short-lived mutexes and you want to clean them up after the last lock has been released, pass the
autoFinalize
option to mortice in the owning context:React native support
This module should run on react native but it only supports single-process concurrency as it's not clear to the author (disclaimer - not a react native dev) what the officially supported process concurrency model is.
Please open an issue if this is a feature you would like to see added.