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>,
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>,
Sourcepub 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>>
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.