Distributed Locking allows a Remote State to be shared among multiple users of the application to make writes appear atomic between sessions. To use it, simply set the locking:
parameter to true
when enabling remote state.
This is how locking works:
StandardError
will be thrownRbcli.remote_state.lock
or Rbcli.remote_state.unlock
, respectively.Remember: all state in Rbcli is lazy-loaded. Therefore, RBCli wll only attempt to lock the data when you first try to access it. If you need to make sure that the data is locked before executing a block of code, use:
Rbcli.remote_state.refresh
to force the lock and retrieve the latest data. You can force an unlock by calling:
Rbcli.remote_state.disconnect
Even if you do not want to store any data, you can leverage manual locking to control access to a different shared resource, such as a stateful API. For example, if you write a cloud deployment toolkit, you can ensure that only one user is attempting to modify a deployment at any given time.