Skip to main content

Executor

Trait Executor 

pub trait Executor:
    Send
    + Sync
    + 'static {
    // Required methods
    fn spawn(
        &self,
        name: &'static str,
        job: Box<dyn FnOnce() + Send>,
    ) -> Result<(), Unsupported>;
    fn wake_at(&self, deadline: Instant, wake: WakeHandle);
    fn park(&self, deadline: Instant);

    // Provided method
    fn now(&self) -> Instant { ... }
}
Expand description

How a host runs background work and timers.

Required Methods§

fn spawn( &self, name: &'static str, job: Box<dyn FnOnce() + Send>, ) -> Result<(), Unsupported>

Run job off the calling thread. name identifies the work in logs.

Implementations must not run job before returning: callers may hold locks the job also takes.

§Errors

Returns Unsupported when this host cannot run background work.

fn wake_at(&self, deadline: Instant, wake: WakeHandle)

Call WakeHandle::wake on wake once now reaches deadline. A deadline already in the past wakes promptly.

fn park(&self, deadline: Instant)

Block until background work may have made progress, or until deadline. For synchronous drivers only (headless capture, tests) — never call this on a live UI thread.

Provided Methods§

fn now(&self) -> Instant

This executor’s clock. Deadlines passed to wake_at are measured against it.

Implementors§