Mutagen is a simple mutex server for the Nitrogen Web Framework. It was previously part of Nitro Cache but has been pulled out and generalized in case a more generalized mutex system is needed for Erlang and/or Nitrogen users.
{deps, [
mutagen
]}.
Either:
- Add it to the
applications
list in your.app.src
file, or - Start it manually with
application:ensure_all_started(mutagen).
Mutagen has a few very simple functions, once the server is running.
-
lock(Key) -> fail | success
: Attempt to lock the mutexKey
. If the mutex is successfully locked, the call will returnsuccess
. If the mutex is already locked, the mutex will returnfail
. -
lock(Key, Timeout) -> fail | success
: Attempt the lock mutexKey
, however, if the mutex is currently already locked, the call will stall and wait up toTimeout
milliseconds before giving up and returningfail
. -
wait(Key) -> free
: Only return when the mutex identified byKey
is free. This does not then lock the mutex, it merely returns when it's available. -
wait(Key, Timeout) -> free | not_free
: Only returnsfree
when the mutex identified byKey
is free, or if the mutex is not free afterTimeout
milliseconds, returnnot_free
. -
status() -> StatusInfo
: Returns a proplist of information related to the number of mutexes that are currently locked, the number of processes queued to lock an already locked mutex, and the number of processes waiting for the mutex to be free.
Apache 2.0 License
Copyright 2023 Jesse Gumm