Skip to main content

WorkerPool

Struct WorkerPool 

Source
pub struct WorkerPool<A: Address, D, J, R, C>
where D: Behavior<Addr = A, Msg = PoolResponse<J, R, A>>, A::Nonce: From<u64>, C: Behavior<Addr = A, Msg = PoolAssignment<J>, Ph = Never>,
{ /* private fields */ }
Expand description

A fixed, homogeneous, bounded FIFO worker pool.

Each configured nonce names one stable supervised proxy. Jobs are assigned only after a successful worker-creation result makes that slot idle. The retained state records an assignment before the corresponding delivery is returned, and a completion must carry the exact assignment token.

§Panics

Admission or retry propagates a panic from the application payload’s Clone implementation before changing pool state. Dispatch panics at the physical assignment-counter boundary before committing its dispatch plan; the executor’s poison-before-step contract makes that actor turn terminal rather than exposing partial successor state. The final counter value is deliberately reserved so every successful batch has a representable successor counter. This is a Bombay implementation boundary, not an actor model law.

A worker with any other message protocol cannot form a pool:

use behavior::{Actions, Behavior, MailAddr, Never, NoBirths, PoolResponse, User, WorkerPool};

struct Reply;
struct WrongWorker;
impl Behavior for Reply {
    type Addr = MailAddr;
    type Msg = PoolResponse<String, (), MailAddr>;
    type Event = User<MailAddr, Self::Msg>;
    type Sends = Vec<Never>;
    type Ph = Never;
    type Error = Never;
    type Birth = NoBirths;
    fn init(&mut self) -> behavior::BehaviorActed<Self> { Ok(Actions::cont()) }
    fn transition(&mut self, _: Self::Event) -> behavior::BehaviorActed<Self> { Ok(Actions::cont()) }
}
impl Behavior for WrongWorker {
    type Addr = MailAddr;
    type Msg = u8;
    type Event = User<MailAddr, u8>;
    type Sends = Vec<behavior::Never>;
    type Ph = Never;
    type Error = Never;
    type Birth = NoBirths;
    fn init(&mut self) -> behavior::BehaviorActed<Self> { unimplemented!() }
    fn transition(&mut self, _: Self::Event) -> behavior::BehaviorActed<Self> { unimplemented!() }
}

// `WrongWorker::Msg` is not `PoolAssignment<String>`.
let _: Option<WorkerPool<MailAddr, Reply, String, (), WrongWorker>> = None;

Implementations§

Source§

impl<A, D, J, R, C> WorkerPool<A, D, J, R, C>
where A: Address, A::Nonce: From<u64>, D: Behavior<Addr = A, Msg = PoolResponse<J, R, A>>, C: Behavior<Addr = A, Msg = PoolAssignment<J>, Ph = Never>,

Source

pub fn new( nonces: fn(usize) -> A::Nonce, count: usize, build: fn(usize) -> C, backlog_capacity: usize, interruption: InterruptionPolicy, restart_policy: RestartPolicy, max_restarts: u32, restart_window: Duration, ) -> Result<Self, PoolConfigError<A::Nonce>>

Construct a pool after proving that every configured child route is unique.

§Errors

Returns PoolConfigError::NoWorkers for an empty topology or PoolConfigError::DuplicateWorker for the first repeated creator-local nonce. No behavior or creation request is produced.

Source

pub fn backlog_len(&self) -> usize

Source

pub fn worker_phase(&self, worker: A::Nonce) -> Option<WorkerPhase>

Trait Implementations§

Source§

impl<A, D, J, R, C> Behavior for WorkerPool<A, D, J, R, C>
where A: Address, A::Nonce: From<u64>, D: Behavior<Addr = A, Msg = PoolResponse<J, R, A>>, J: Clone, C: Behavior<Addr = A, Msg = PoolAssignment<J>, Ph = Never>,

Source§

type Addr = A

Source§

type Msg = PoolMessage<A, D, J, R>

Source§

type Event = SupervisionEvent<User<A, PoolMessage<A, D, J, R>>>

Source§

type Sends = SupervisorSends<A, PoolBehaviorSends<A, D, J, R, C>, C>

Source§

type Ph = Never

Source§

type Error = PoolError<<A as Address>::Nonce>

Source§

type Birth = Births<Proxy<C>>

Source§

fn init(&mut self) -> BehaviorActed<Self>

Produce initialization actions before the first event is accepted. Read more
Source§

fn transition(&mut self, event: Self::Event) -> BehaviorActed<Self>

Fold exactly one event into explicit actions and the next behavior. Read more
Source§

fn receive( &mut self, from: Self::Addr, message: Self::Msg, ) -> BehaviorActed<Self>
where Self: Sized,

Fold one user communication through the composed protocol. Read more
Source§

fn on<Input>(&mut self, input: Input) -> BehaviorActed<Self>
where Self: Sized, Self::Event: EventInput<Input>,

Inject one supported semantic input and fold it through this behavior. Read more

Auto Trait Implementations§

§

impl<A, D, J, R, C> Freeze for WorkerPool<A, D, J, R, C>
where <A as Address>::Nonce: Sized,

§

impl<A, D, J, R, C> RefUnwindSafe for WorkerPool<A, D, J, R, C>

§

impl<A, D, J, R, C> Send for WorkerPool<A, D, J, R, C>
where <A as Address>::Nonce: Sized + Send, J: Send, A: Send,

§

impl<A, D, J, R, C> Sync for WorkerPool<A, D, J, R, C>
where <A as Address>::Nonce: Sized + Sync, J: Sync, A: Sync,

§

impl<A, D, J, R, C> Unpin for WorkerPool<A, D, J, R, C>
where <A as Address>::Nonce: Sized + Unpin, J: Unpin, A: Unpin,

§

impl<A, D, J, R, C> UnsafeUnpin for WorkerPool<A, D, J, R, C>
where <A as Address>::Nonce: Sized,

§

impl<A, D, J, R, C> UnwindSafe for WorkerPool<A, D, J, R, C>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.