rama::layer::limit::policy

Trait ConcurrentTracker

pub trait ConcurrentTracker:
    Send
    + Sync
    + 'static {
    type Guard: Send + 'static;
    type Error: Send + Sync + 'static;

    // Required method
    fn try_access(&self) -> Result<Self::Guard, Self::Error>;
}
Expand description

The tracker trait that can be implemented to provide custom concurrent request tracking.

By default ConcurrentCounter is provided, but in case you need multi-instance tracking, you can support that by implementing the ConcurrentTracker trait.

Required Associated Types§

type Guard: Send + 'static

The guard that is used to consume a resource and that is expected to release the resource when dropped.

type Error: Send + Sync + 'static

The error that is returned when the concurrent request limit is reached, which is also returned in case a used backoff failed.

Required Methods§

fn try_access(&self) -> Result<Self::Guard, Self::Error>

Try to access the resource, returning a guard if successful, or an error if the limit is reached.

When the limit is reached and a backoff is used in the parent structure, the backoff should tried to be used before returning the error.

Implementors§

§

impl ConcurrentTracker for ConcurrentCounter

§

type Guard = ConcurrentCounterGuard

§

type Error = LimitReached