pub trait Reactor: Send + Sync + Sized {
    // Required methods
    fn new() -> Result<Self>;
    fn on_executor_drop<'a>(&'a self) -> Pin<Box<dyn Future<Output = ()> + 'a>>;
    fn wait_for_work(&self, set_processing: impl Fn()) -> Result<()>;
    fn wake(&self);
    fn new_source<F: AsRawDescriptor>(
        &self,
        ex: &Arc<RawExecutor<Self>>,
        f: F
    ) -> AsyncResult<IoSource<F>>;
    fn wrap_task_handle<R>(task: RawTaskHandle<Self, R>) -> TaskHandle<R> ;

    // Provided method
    fn on_thread_start(&self) { ... }
}
Expand description

Abstraction for IO backends.

Required Methods§

source

fn new() -> Result<Self>

source

fn on_executor_drop<'a>(&'a self) -> Pin<Box<dyn Future<Output = ()> + 'a>>

Called when the executor is being dropped to allow orderly shutdown (e.g. cancelling IO work). The returned future will be run to completion.

Note that, since this is called from RawExecutor::drop, there will not be any Arc<Executor> left, so weak references to the executor will always fail to upgrade at this point. Reactors can potentially make use of this fact to keep more IO work from being submitted.

source

fn wait_for_work(&self, set_processing: impl Fn()) -> Result<()>

Block until an event occurs (e.g. IO work is ready) or until wake is called.

As an optimization, set_processing should be called immediately after wake up (i.e. before any book keeping is done) so that concurrent calls to wakers can safely skip making redundant calls to Reactor::wake.

source

fn wake(&self)

Wake up any pending wait_for_work calls. If there are none pending, then wake up the next wait_for_work call (necessary to avoid race conditions).

source

fn new_source<F: AsRawDescriptor>( &self, ex: &Arc<RawExecutor<Self>>, f: F ) -> AsyncResult<IoSource<F>>

Create an IoSource for the backend.

source

fn wrap_task_handle<R>(task: RawTaskHandle<Self, R>) -> TaskHandle<R>

Provided Methods§

source

fn on_thread_start(&self)

Called when an executor run loop starts on a thread.

Object Safety§

This trait is not object safe.

Implementors§