Crates.io | logic-lock |
lib.rs | logic-lock |
version | 0.12.0 |
source | src |
created_at | 2022-11-07 08:35:49.253322 |
updated_at | 2023-08-18 07:17:52.7394 |
description | MySQL logic locks implemented over sea-orm |
homepage | |
repository | https://github.com/nappa85/logic-lock |
max_upload_size | |
id | 707097 |
size | 16,575 |
MySQL logic locks implemented over sea-orm
Lock::build
takes a key, any owned connection, so it can be a sea-orm::DatabaseConnection
, a sea-orm::DatabaseTransaction
or another Lock
himself, and an optional timeout in seconds, defaulting to 1 second.
In case of error, the owned connection is returned alongside the database error, if any, this way the connection isn't automatically dropped.
Lock
himself acts as a connection, so you can use it everywhere you would have used the original connection.
let lock = logic_lock::Lock::build("my_lock_key", conn, None).await.unwrap();
Since MySQL logic locks lives in the session, not in a transaction like table locks, a not-dropped lock will live as long as the connection, and if a connection is part of a connection pool, this can be a really long time.
To release a Lock
simply use the Lock::release
method.
On success it will return the original connection, on error it will return the Lock
himself alongside with the database error, if any.
let conn = lock.release().await.unwrap();
Dropping a locked Lock
will log an error.
It has been chosen to not panic to avoid cases of panic-while-panicking.