Skip to main content

ResourcePolicy

Trait ResourcePolicy 

Source
pub trait ResourcePolicy:
    Send
    + Sync
    + 'static {
    // Provided methods
    fn admit_actor(&self) -> Result<()> { ... }
    fn release_actor(&self) { ... }
    fn admit_message(&self, count: usize) -> Result<()> { ... }
}
Expand description

Admission control for actor spawns and message sends.

Called synchronously on the hot path (spawn, send, send_batch), so implementations must be cheap and non-blocking.

All methods have default implementations that admit everything, so policies only need to override what they enforce.

Provided Methods§

Source

fn admit_actor(&self) -> Result<()>

Decide whether a new actor may be spawned.

Return Err(reason) to reject the spawn; the reason is surfaced in the Error::ResourceExhausted message.

Source

fn release_actor(&self)

Notify the policy that an actor was killed/released.

Called from ActorScheduler::kill. Use to free any per-actor budget.

Source

fn admit_message(&self, count: usize) -> Result<()>

Decide whether a send of count messages may proceed.

count == 1 for single sends, > 1 for batch sends.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§