Trait cros_async::common_executor::Reactor
source · 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§
fn new() -> Result<Self>
sourcefn on_executor_drop<'a>(&'a self) -> Pin<Box<dyn Future<Output = ()> + 'a>>
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.
sourcefn wait_for_work(&self, set_processing: impl Fn()) -> Result<()>
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
.
sourcefn wake(&self)
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).
sourcefn new_source<F: AsRawDescriptor>(
&self,
ex: &Arc<RawExecutor<Self>>,
f: F
) -> AsyncResult<IoSource<F>>
fn new_source<F: AsRawDescriptor>( &self, ex: &Arc<RawExecutor<Self>>, f: F ) -> AsyncResult<IoSource<F>>
Create an IoSource
for the backend.
fn wrap_task_handle<R>(task: RawTaskHandle<Self, R>) -> TaskHandle<R> ⓘ
Provided Methods§
sourcefn on_thread_start(&self)
fn on_thread_start(&self)
Called when an executor run loop starts on a thread.