pub trait PoolItem: Debugwhere
    Self: Sized,
    Self::Init: Send + IdTargeted + RequestWithResponse<Self, Response = AddResponse>,
    Self::Api: Debug + Send + IdTargeted,{
    type Init;
    type Api;

    // Required methods
    fn process_message(
        &mut self,
        request: Self::Api
    ) -> ThreadRequestResponse<Self>;
    fn new_pool_item(request: Self::Init) -> Result<Self, NewPoolItemError>;

    // Provided methods
    fn id_not_found(request: &Self::Api) -> ThreadRequestResponse<Self> { ... }
    fn name() -> &'static str { ... }
    fn shutdown_pool(&self) -> Vec<ThreadShutdownResponse> { ... }
    fn add_pool_item_tracing(&self) -> Option<Vec<Box<dyn GuardDrop>>> { ... }
    fn add_pool_thread_tracing(
        id: usize
    ) -> Option<(DefaultGuard, Vec<WorkerGuard>)> { ... }
}
Expand description

This is the trait that needs to be implemented by a struct in order that it can be managed by the thread pool infrastructure

Required Associated Types§

source

type Init

This is a struct that defines the message that will initiate a new instance of the struct within the thread pool

source

type Api

This is the enum that will define that messaging api that can be used to communicate with instances of the struct It will be an enum where each variant will define a request/response pair of structs

Required Methods§

source

fn process_message(&mut self, request: Self::Api) -> ThreadRequestResponse<Self>

This is the function that will define how the struct processes the messages that it receives. It will typically consist of a match statement that will discriminate amongst the various messages type defined in the Api

source

fn new_pool_item(request: Self::Init) -> Result<Self, NewPoolItemError>

This function defines how a new struct will be created when it receives The Init message. It returns the created new instance of the struct

Provided Methods§

source

fn id_not_found(request: &Self::Api) -> ThreadRequestResponse<Self>

The function called if an item with the specified is not found The default behaviour is to panic

source

fn name() -> &'static str

used for debug only; allows logging to output the name of the type

source

fn shutdown_pool(&self) -> Vec<ThreadShutdownResponse>

This function is a hook that is called when the pool is shutting down.

source

fn add_pool_item_tracing(&self) -> Option<Vec<Box<dyn GuardDrop>>>

This method is called to optionally add tracing before each message is processed. The tracing is removed once the message is processed. If the tracing is being written to a file it is important that the file is not truncated The implementation needs to return a vec of guards of any subscribers added.

source

fn add_pool_thread_tracing( id: usize ) -> Option<(DefaultGuard, Vec<WorkerGuard>)>

This method provides any required tracing in the pool items thread pool threads This tracing is added when the thread is spawned and remains in place until the thread dies

Implementors§

source§

impl PoolItem for Randoms

The implementation of this trait allows the Randoms struct to be used in the thread pool infrastructure

source§

impl<P> PoolItem for RandomsBatch<P>where P: SenderAndReceiver<Randoms> + Send + Sync + Debug,