ThreadPoolExecutor

Struct ThreadPoolExecutor 

Source
pub struct ThreadPoolExecutor<ID: PartialEq> { /* private fields */ }
Expand description

ThreadPool Executor

The ThreadPool Executor stores Nodes in a sorted vector and sends them to be executed by the threadPool.

Note: The ThreadPool Executor ca be interrupted by sending a true value over the mpsc channel whose receiving end is owned by the ThreadPool executor.

Addendum: The main thread of the ThreadPool is conducting the scheduling so the ThreadPool will only have n-1 worker threads where n is the total number of threads allocated to the threadpool executor.

Implementations§

Source§

impl<ID: PartialEq> ThreadPoolExecutor<ID>

Source

pub fn new(threads: usize, interrupt: Receiver<bool>) -> Self

Creates a new ThreadPool executor without any Nodes

Source

pub fn new_with( threads: usize, interrupt: Receiver<bool>, nodes: Vec<Box<dyn Node<ID>>>, ) -> Self

Creates a new ThreadPool Executor with a number of Nodes

Trait Implementations§

Source§

impl<ID: PartialEq + 'static> Executor<ID> for ThreadPoolExecutor<ID>

Source§

type Context = Box<dyn Any>

Context doesn’t really apply to Threadpool executors

Source§

fn start(&mut self)

For each node in the ThreadPool executor the node will be updated and start_instant will be set to the current instant

Note: this should probably not be called individually because it will always be called at the beginning of update_for_ms or update_loop

Source§

fn check_interrupt(&mut self) -> bool

Check the interrupt receiver for an interrupt

Source§

fn add_node(&mut self, node: Box<dyn Node<ID>>)

Add a node to the ThreadPool Executor.

Note: Nodes can only be added to the executor when it is not running.

Additionally, only 1 node can exist per id so additional nodes added with the same id will replace the previous node of a given id

Source§

fn remove_node(&mut self, id: &ID) -> Option<Box<dyn Node<ID>>>

Remove a node from the Threadpool Executor.

Note: Nodes can only be removed from hte executor when it is not running

Source§

fn update_for_ms(&mut self, ms: u128)

Run the update loop for a set amount of time (in milliseconds)
Source§

fn update_loop(&mut self)

Run the update loop until the executor’s interrupt is called
Source§

fn add_node_with_context( &mut self, node: Box<dyn Node<ID>>, _ctx: Self::Context, )

Add a node to the executor with some given context. Read more

Auto Trait Implementations§

§

impl<ID> Freeze for ThreadPoolExecutor<ID>

§

impl<ID> !RefUnwindSafe for ThreadPoolExecutor<ID>

§

impl<ID> Send for ThreadPoolExecutor<ID>

§

impl<ID> !Sync for ThreadPoolExecutor<ID>

§

impl<ID> Unpin for ThreadPoolExecutor<ID>

§

impl<ID> !UnwindSafe for ThreadPoolExecutor<ID>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.