Skip to content

FlixCoder/key-lock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KeyLock

crates.io page docs.rs page license: MIT

Simple library for mutual exclusion based on keys. Lock and wait for execution by key.

Usage

Import the project using:

cargo add key-lock

Example

use key_lock::KeyLock;

#[tokio::main]
async fn main() {
    // Initialize new lock.
    let lock = KeyLock::new();
    // Lock A, continues immediately.
    let _a = lock.lock("a").await;
    // Lock B, continues immediately.
    let _b = lock.lock("b").await;
    // Try to lock A, but it is already locked. Normal locking would block here.
    assert!(lock.try_lock("a").await.is_err());
}

Minimum supported Rust version

Currently, I am always using the latest stable Rust version and do not put in effort to keep the MSRV. Please open an issue in case you need a different policy, I might consider changing the policy.

License

Licensed under the MIT license. All contributors agree to license under this license.

About

Library for mutual exclusion by keys.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages