SimpleExecutor

Struct SimpleExecutor 

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

Simple Executor

This simple executor stores Nodes in a sorted vector where the priority is higher the closer to the current timestamp the Node’s next update is.

Note: The Simple Executor can be interrupted by sending a true value over the mpsc channel whose receiving end is owned by the SimpleExecutor

Addendum: The Simple Executor will also busy wait between node executions so do not expect the SimpleExecutor to yield CPU time to other processes while it is running.

Implementations§

Source§

impl<ID: PartialEq> SimpleExecutor<ID>

Source

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

Create a new Simple Executor without any Nodes

Source

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

Creates a new Simple Executor with a number of Nodes

Trait Implementations§

Source§

impl<ID: PartialEq> Executor<ID> for SimpleExecutor<ID>

Source§

type Context = Box<dyn Any>

Context doesn’t really apply to SimpleExecutors

Source§

fn start(&mut self)

For each node in the simple executor we should reset their priority to 0 and start the node. We should also set the start_instant to the current time.

Note: this method should not be called individually as it will always be called during the update_for_ms and update_loop methods so running it here is completely redundant.

Source§

fn update_for_ms(&mut self, ms: u128)

Start the executor and run the executor for a given number of milliseconds before stopping the executor. An interrupt will also stop the executor early.

Note: if there are no Nodes currently in the executor it will busy wait until the time has passed or an interrupt occurs

Source§

fn update_loop(&mut self)

Start the executor and run until an interrupt is received.

Note: if there are no Nodes currently in the executor it will busy wait until it receives an interrupt

Source§

fn check_interrupt(&mut self) -> bool

Check the interrupt receiver for an interrupt. If an interrupt signal was sent over the channel then this node should report that it was interrupted.

Source§

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

Add a node to the Simple 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 Simple Executor.

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

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 SimpleExecutor<ID>

§

impl<ID> !RefUnwindSafe for SimpleExecutor<ID>

§

impl<ID> Send for SimpleExecutor<ID>

§

impl<ID> !Sync for SimpleExecutor<ID>

§

impl<ID> Unpin for SimpleExecutor<ID>

§

impl<ID> !UnwindSafe for SimpleExecutor<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.