Skip to main content

Executor

Struct Executor 

Source
pub struct Executor { /* private fields */ }
Expand description

Task executor for synchronous task processing.

Provides a simple run-to-completion model where tasks are executed one at a time. Panics are caught to prevent runtime crashes.

Implementations§

Source§

impl Executor

Source

pub const fn new(work_queue: Arc<WorkQueue>) -> Self

Create a new executor with a shared work queue.

Source

pub fn with_batch_size(self, size: usize) -> Self

Set the batch size for processing.

The batch size limits how many tasks are processed per tick() call.

Source

pub fn tick(&mut self) -> usize

Process one tick (up to batch_size tasks).

Returns the total number of tasks processed (successful + failed).

Source

pub fn execute_task(task: &mut Task) -> bool

Execute a single task with panic handling.

Returns true if the task completed successfully, false if it failed or panicked.

Source

pub fn schedule(&self, task: Task) -> bool

Schedule a task for execution.

Returns false if the queue is full.

Source

pub fn spawn<F>(&self, work: F) -> bool
where F: FnOnce() + Send + 'static,

Schedule work using a closure.

Convenience method that creates a task with normal priority.

Source

pub const fn executed_count(&self) -> u64

Get the total number of successfully executed tasks.

Source

pub const fn failed_count(&self) -> u64

Get the total number of failed tasks.

Source

pub fn has_pending(&self) -> bool

Check if there’s pending work.

Source

pub const fn batch_size(&self) -> usize

Get the current batch size.

Source

pub fn drain(&mut self) -> usize

Drain all pending tasks, executing each one.

Returns the total number of tasks processed.

Source

pub const fn reset_stats(&mut self)

Reset execution statistics.

Trait Implementations§

Source§

impl Debug for Executor

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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, 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.