Struct messaging_thread_pool::samples::Randoms
source · Expand description
This represents a simple collection of random numbers which is hosted inside the thread pool
It is tied to a particular thread by the modulus of its id.
The interface that it supports is governed by its implementation of the PoolItem trait. This in turn needs to be supported by the use of two enums of supported requests and responses
It supports the following operations Init creates a new Random with an stack based store of random numbers Mean calculates the mean of the contained numbers Sum calculates the sum of the contained numbers
Fields§
§id: usize§numbers: Vec<u64>Implementations§
Trait Implementations§
source§impl PoolItem for Randoms
impl PoolItem for Randoms
The implementation of this trait allows the Randoms struct to be used in the thread pool infrastructure
source§fn process_message(&mut self, request: Self::Api) -> ThreadRequestResponse<Self>
fn process_message(&mut self, request: Self::Api) -> ThreadRequestResponse<Self>
here
§type Init = RandomsAddRequest
type Init = RandomsAddRequest
This is a struct that defines the message that will initiate a new instance
of the struct within the thread pool Read more
§type Api = RandomsApi
type Api = RandomsApi
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 Read more
source§fn new_pool_item(request: Self::Init) -> Result<Self, NewPoolItemError>
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 Read more
source§fn shutdown_pool(&self) -> Vec<ThreadShutdownResponse>
fn shutdown_pool(&self) -> Vec<ThreadShutdownResponse>
This function is a hook that is called when the pool is shutting down.
source§fn id_not_found(request: &Self::Api) -> ThreadRequestResponse<Self>
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 Read more
source§fn add_element_request_tracing(
id: usize
) -> Option<(DefaultGuard, Vec<WorkerGuard>)>
fn add_element_request_tracing(
id: usize
) -> Option<(DefaultGuard, Vec<WorkerGuard>)>
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 Read more
source§fn add_pool_thread_tracing(
id: usize
) -> Option<(DefaultGuard, Vec<WorkerGuard>)>
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 Read more