Skip to main content

Executor

Struct Executor 

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

A single-threaded async task executor with priority queues.

Each Executor manages its own task slots, ready queues, and deferred callback buffers. Use Executor::new_instance to create an isolated executor (e.g. per SSR request), or use the global thread-local executor via spawn_global.

Implementations§

Source§

impl Executor

Source

pub fn active_task_count(&self) -> usize

Return the number of currently active (not-yet-completed) tasks.

Used by streaming SSR to determine whether the stream should wait for more work or terminate.

Source§

impl Executor

Source

pub fn new_instance() -> Rc<RefCell<Executor>>

Create a new isolated executor, wrapped for shared access.

The returned executor is independent of the global thread-local executor. Use with_executor to make it the current executor for the duration of a closure, so that spawned tasks and signal callbacks are routed to it.

Source

pub fn install_flush_scheduler( ex: &Rc<RefCell<Executor>>, sched: Rc<dyn ScheduleFlush>, )

Install a flush scheduler on this executor instance.

Source

pub fn install_time_source(ex: &Rc<RefCell<Executor>>, ts: Rc<dyn TimeSource>)

Install a time source on this executor instance.

Source

pub fn set_time_budget(ex: &Rc<RefCell<Executor>>, budget_ms: u64)

Set the maximum time (in milliseconds) a single flush may spend before yielding back to the host event loop.

The default is 8 ms. Set to u64::MAX to disable time-budget yielding (flush runs to completion).

Source

pub fn set_panic_hook(ex: &Rc<RefCell<Executor>>, hook: Rc<dyn Fn(PanicInfo)>)

Register a callback invoked whenever a spawned task panics.

The default is no hook — panicking tasks are silently removed from the executor (the same behaviour as a task returning Poll::Ready(())).

§Example
Executor::set_panic_hook(&ex, Rc::new(|info| {
    eprintln!("task {} in scope {} panicked", info.task_id, info.scope_id);
}));
Source

pub fn spawn( ex: &Rc<RefCell<Executor>>, future: impl Future<Output = ()> + 'static, )

Spawn a future on this executor instance.

Source

pub fn flush_instance(ex: &Rc<RefCell<Executor>>)

Run a full flush cycle on this executor instance.

Mirrors the global flush cycle but operates on an isolated executor (used for SSR). Includes all the same protections: catch_unwind, suspend checks, time-budget yielding, and callback-drain budget.

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.