Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

made the API safer #2

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rust-etcd-utils"
version = "0.1.0"
version = "0.2.0"
edition = "2021"

[dependencies]
Expand Down
14 changes: 7 additions & 7 deletions src/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl Future for LockManagerHandle {
}

#[derive(Clone)]
pub struct ManagedLockDeleteCallback {
pub struct ManagedLockRevokeNotify {
watch_lock_delete: broadcast::Sender<Revision>,
}

Expand All @@ -71,8 +71,8 @@ impl fmt::Display for LockDeleteCallbackError {
}
}

impl ManagedLockDeleteCallback {
pub async fn wait_for_revoke(&self) -> Result<Revision, LockDeleteCallbackError> {
impl ManagedLockRevokeNotify {
pub async fn wait_for_revoke(self) -> Result<Revision, LockDeleteCallbackError> {
self.watch_lock_delete
.subscribe()
.recv()
Expand Down Expand Up @@ -230,16 +230,16 @@ impl LockManager {
where
S: AsRef<str>,
{
self.try_lock_with_revoke_callback(name, lease_duration)
self.try_lock_return_revoke_notify(name, lease_duration)
.await
.map(|(lock, _)| lock)
}

pub async fn try_lock_with_revoke_callback<S>(
pub async fn try_lock_return_revoke_notify<S>(
&self,
name: S,
lease_duration: Duration,
) -> Result<(ManagedLock, ManagedLockDeleteCallback), TryLockError>
) -> Result<(ManagedLock, ManagedLockRevokeNotify), TryLockError>
where
S: AsRef<str>,
{
Expand Down Expand Up @@ -300,7 +300,7 @@ impl LockManager {
delete_signal_tx: self.delete_queue_tx.clone(),
revoke_callback_tx: watch_lock_delete.clone(),
},
ManagedLockDeleteCallback { watch_lock_delete },
ManagedLockRevokeNotify { watch_lock_delete },
))
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async fn dropping_managed_lock_should_revoke_etcd_lock() {
let lock_name = random_str(10);

let (managed_lock1, delete_cb) = lock_man
.try_lock_with_revoke_callback(lock_name.as_str(), Duration::from_secs(10))
.try_lock_return_revoke_notify(lock_name.as_str(), Duration::from_secs(10))
.await
.expect("failed to lock");

Expand Down
Loading