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.
Assignment-sequence exhaustion is a typed PoolError::SequenceExhausted
rejection selected before backlog or slot state is changed. As with any
generic Rust API, a user-provided Clone implementation can itself unwind;
the pool introduces no panic path of its own.
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, _: crate::InitializationTurn) -> behavior::BehaviorActed<Self> { Ok(Actions::cont()) }
fn transition(&mut self, _: crate::ActiveTurn, _: 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, _: crate::InitializationTurn) -> behavior::BehaviorActed<Self> { Ok(Actions::cont()) }
fn transition(&mut self, _: crate::ActiveTurn, _: Self::Event) -> behavior::BehaviorActed<Self> { Ok(Actions::cont()) }
}
// `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) -> Option<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) -> Option<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.