arbitrary-lock 0.1.1

Lock by arbitrary keys
Documentation
  • Coverage
  • 11.11%
    1 out of 9 items documented0 out of 8 items with examples
  • Size
  • Source code size: 7.25 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 438.48 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 15s Average build duration of successful builds.
  • all releases: 15s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • wilsonzlin

arbitrary-lock

Acquire a lock on an arbitrary key, like a string or integer.

Usage

Add the dependency to your project:

cargo add arbitrary-lock

Use the struct:

// This can be cheaply cloned.
// The key must be Hash + Eq + Clone.
// Provide your preferred lock type as the second generic argument. It must implement Default.
let locker = ArbitraryLock::<String, tokio::sync::Mutex<()>>::new();
{
  let _l = locker.get("user:2185724".to_string()).lock().await;
  do_something_in_database().await;
};