Skip to content

Commit

Permalink
made the API safer
Browse files Browse the repository at this point in the history
  • Loading branch information
lvboudre committed Nov 21, 2024
1 parent 6dee44e commit 05e4e61
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
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

0 comments on commit 05e4e61

Please sign in to comment.