pub struct RandomsBatch<P>where
    P: SenderAndReceiver<Randoms>,{
    pub id: usize,
    pub contained_random_ids: Vec<usize>,
    pub id_provider: Arc<dyn IdProvider>,
    pub randoms_thread_pool: Arc<P>,
}
Expand description

An example of an element that contains a child thread pool

RandomsBatches and Randoms form a hierarchy. A RandomsBatch contains many Randoms.

RandomsBatches are managed by a one thread pool and internally they have a collection of Randoms which are managed in a separate “child” thread pool In this example all of the Randoms share a single thread pool regardless of which RandomsBatch created them

For this reason the RandomsBatches need to share an id_provider which provides globally unique ids (ids, must be unique across the thread pool for obvious reasons)

Fields§

§id: usize§contained_random_ids: Vec<usize>§id_provider: Arc<dyn IdProvider>§randoms_thread_pool: Arc<P>

Implementations§

source§

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

source

pub fn new(add_request: RandomsBatchAddRequest<P>) -> Self

source

pub fn randoms_thread_pool(&self) -> &P

source

pub fn sum_of_sums(&self) -> u128

source

pub fn contained_random_ids_mut(&mut self) -> &mut Vec<usize>

Trait Implementations§

source§

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

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

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

§

type Init = RandomsBatchAddRequest<P>

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

type Api = RandomsBatchApi<P>

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
source§

fn name() -> &'static str

used for debug only; allows logging to output the name of the type
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
source§

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>

The function called if an item with the specified is not found The default behaviour is to panic
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
source§

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

source§

impl<P> RequestWithResponse<RandomsBatch<P>> for SumOfSumsRequestwhere P: SenderAndReceiver<Randoms> + Send + Debug + Sync,

ties together the request with a response

Auto Trait Implementations§

§

impl<P> !RefUnwindSafe for RandomsBatch<P>

§

impl<P> Send for RandomsBatch<P>where P: Send + Sync,

§

impl<P> Sync for RandomsBatch<P>where P: Send + Sync,

§

impl<P> Unpin for RandomsBatch<P>

§

impl<P> !UnwindSafe for RandomsBatch<P>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

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

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more