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
impl Executor
Sourcepub fn active_task_count(&self) -> usize
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
impl Executor
Sourcepub fn new_instance() -> Rc<RefCell<Executor>>
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.
Sourcepub fn install_flush_scheduler(
ex: &Rc<RefCell<Executor>>,
sched: Rc<dyn ScheduleFlush>,
)
pub fn install_flush_scheduler( ex: &Rc<RefCell<Executor>>, sched: Rc<dyn ScheduleFlush>, )
Install a flush scheduler on this executor instance.
Sourcepub fn install_time_source(ex: &Rc<RefCell<Executor>>, ts: Rc<dyn TimeSource>)
pub fn install_time_source(ex: &Rc<RefCell<Executor>>, ts: Rc<dyn TimeSource>)
Install a time source on this executor instance.
Sourcepub fn set_time_budget(ex: &Rc<RefCell<Executor>>, budget_ms: u64)
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).
Sourcepub fn set_panic_hook(ex: &Rc<RefCell<Executor>>, hook: Rc<dyn Fn(PanicInfo)>)
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);
}));Sourcepub fn spawn(
ex: &Rc<RefCell<Executor>>,
future: impl Future<Output = ()> + 'static,
)
pub fn spawn( ex: &Rc<RefCell<Executor>>, future: impl Future<Output = ()> + 'static, )
Spawn a future on this executor instance.
Sourcepub fn flush_instance(ex: &Rc<RefCell<Executor>>)
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.