[−][src]Struct throttle_client::Client
Send http requests to a throttle server. Only concerned with sending correct HTTP requests the Throttle server understands. Not a higher level locking library.
Implementations
impl Client
[src]
pub fn new(url: impl IntoUrl) -> Result<Self, Error>
[src]
A new throttle Client instance.
pub async fn new_peer<'_>(&'_ self, expires_in: Duration) -> Result<u64, Error>
[src]
Register a new peer with the server.
Parameters
expires_in
: Retention time of the peer on the server. A peer is used to acquire locks and keep the leases to them alive. A Peer owns the locks which it acquires and releasing it is going to release the owned locks as well.
Every call to new_peer
should be matched by a call to release
.
Creating a peer new_peer
is separated from acquire
in an extra Request mostly to make
acquire
idempotent. This prevents a call to acquire from acquiring more than one
semaphore in case it is repeated due to a timeout.
pub async fn release<'_>(&'_ self, peer_id: u64) -> Result<(), Error>
[src]
Deletes the peer on the throttle server.
This is important to unblock other clients which may be waiting for the semaphore remainder to increase.
pub async fn acquire<'_, '_>(
&'_ self,
peer_id: u64,
semaphore: &'_ str,
count: u32,
expires_in: Option<Duration>,
block_for: Option<Duration>
) -> Result<bool, Error>
[src]
&'_ self,
peer_id: u64,
semaphore: &'_ str,
count: u32,
expires_in: Option<Duration>,
block_for: Option<Duration>
) -> Result<bool, Error>
Acquire a lock from the server.
Every call to acquire
should be matched by a call to release
. Check out
lock
which as contextmanager does this for you.
Parameters
semaphore
: Name of the semaphore to be acquired.count
: The count of the lock. A larger count represents a larger 'piece' of the resource under procection.block_for
: The request returns as soon as the lock could be acquireod or after the duration has elapsed, even if the lock could not be acquired. If set toNone
, the request returns immediatly. Please note that this function is asynchronous and does not block. The blocking does refer to the actual request. As suchblock_for
represents an upper bound after which the returned futures poll method is going to returnReady
.expires_in
: The amount of time the remains valid. Can be prolonged by calling heartbeat. After the time has passed the lock is considered released on the server side.
Return
true
if the lock is active, false
otherwise.
pub async fn is_acquired<'_>(&'_ self, peer_id: u64) -> Result<bool, Error>
[src]
Ask the server wether the peer has acquired all its locks.
pub async fn remove_expired<'_>(&'_ self) -> Result<usize, Error>
[src]
pub async fn remainder<'_, '_>(
&'_ self,
semaphore: &'_ str
) -> Result<i64, Error>
[src]
&'_ self,
semaphore: &'_ str
) -> Result<i64, Error>
The curent semaphore count. I.e. the number of available leases
This is equal to the full semaphore count minus the current count. This number could become negative, if the semaphores have been overcommitted (due to previously reoccuring leases previously considered dead).
pub async fn restore<'_, '_>(
&'_ self,
peer_id: u64,
acquired: &'_ HashMap<String, u32>,
expires_in: Duration
) -> Result<(), Error>
[src]
&'_ self,
peer_id: u64,
acquired: &'_ HashMap<String, u32>,
expires_in: Duration
) -> Result<(), Error>
Sends a restore request to the server.
This request creates a peer with the specified peer id. The peer is also going to hold all the locks passed in acquired, even if this means exceeding the semaphore count.
pub async fn heartbeat<'_>(
&'_ self,
peer_id: u64,
expires_in: Duration
) -> Result<(), Error>
[src]
&'_ self,
peer_id: u64,
expires_in: Duration
) -> Result<(), Error>
Send a PUT request to the server updating the expiration timestamp
pub async fn release_lock<'_, '_>(
&'_ self,
peer_id: u64,
semaphore: &'_ str
) -> Result<(), Error>
[src]
&'_ self,
peer_id: u64,
semaphore: &'_ str
) -> Result<(), Error>
Release a lock to a semaphore for a specific peer
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,