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§
Trait Implementations§
Source§impl<ID: PartialEq> Executor<ID> for SimpleExecutor<ID>
impl<ID: PartialEq> Executor<ID> for SimpleExecutor<ID>
Source§fn start(&mut self)
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)
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)
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
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>>)
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.