Skip to content

Concurrency Limiting ABCs#

ConcurrencyLimiterProto #

Bases: Protocol[ClientT]

A protocol for valid concurrency limiters that arc can use.

Tip

An easy (but not necessary) way to ensure you've implemented all methods is to inherit from this protocol.

limit abstractmethod property #

limit: int

The limit of the concurrency limiter.

acquire abstractmethod async #

acquire(ctx: Context[ClientT]) -> None

Acquire a concurrency slot for a context.

This should block until a slot is available.

is_exhausted abstractmethod #

is_exhausted(ctx: Context[ClientT]) -> bool

Return whether the concurrency limiter is exhausted for a context.

release abstractmethod #

release(ctx: Context[ClientT]) -> None

Release a concurrency slot for a context.

HasConcurrencyLimiter #

Bases: ABC, Generic[ClientT]

A trait for objects that can have a concurrency limiter.

concurrency_limiter abstractmethod property writable #

concurrency_limiter: ConcurrencyLimiterProto[ClientT] | None

The concurrency limiter for this object.

set_concurrency_limiter #

set_concurrency_limiter(limiter: ConcurrencyLimiterProto[ClientT]) -> Self

Set the concurrency limiter for this object.

with_concurrency_limit #

with_concurrency_limit(
    limiter: ConcurrencyLimiterProto[ClientT],
) -> Callable[[HasConcurrencyLimiterT], HasConcurrencyLimiterT]

A decorator that sets a concurrency limiter for an object.

Note

An object can only have one concurrency limiter set at a time.

PARAMETER DESCRIPTION
limiter

The concurrency limiter to use.

TYPE: ConcurrencyLimiterProto[ClientT]

RETURNS DESCRIPTION
Callable[[HasConcurrencyLimiterT], HasConcurrencyLimiterT]

The object with the concurrency limiter set.

Example
@client.include
# Max 5 users can use this command at a time.
@arc.with_concurrency_limit(arc.user_concurrency(5))
@arc.slash_command(...)
async def foo(ctx: arc.GatewayContext) -> None:
    ...
See Also