pub struct MainThreadExecutor {}Expand description
An executor that runs futures on the application’s main thread.
MainThreadExecutor implements the some_executor traits (SomeExecutor,
SomeLocalExecutor, and SomeStaticExecutor), allowing it to be used with
any code that accepts executor-agnostic task spawning.
This executor integrates with the platform’s native event loop, ensuring futures can yield control back to the OS for smooth operation. All futures spawned on this executor will run on the main thread, which is required for UI operations on many platforms.
§Example
use app_window::some_executor::MainThreadExecutor;
use some_executor::SomeExecutor;
let mut executor = MainThreadExecutor {};
// Spawn a task on the main thread
// let task = Task::new("my_task".to_string(), async {
// // This runs on the main thread
// println!("Hello from main thread!");
// });
// let observer = executor.spawn(task);§Integration
When application::main() is called, a MainThreadExecutor
is automatically installed as both the thread-local and thread-static executor, making
it available to any code using the some_executor crate’s convenience functions.
Trait Implementations§
Source§impl Clone for MainThreadExecutor
impl Clone for MainThreadExecutor
Source§fn clone(&self) -> MainThreadExecutor
fn clone(&self) -> MainThreadExecutor
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MainThreadExecutor
impl Debug for MainThreadExecutor
impl LocalExecutorExt<'static> for MainThreadExecutor
Source§impl SomeExecutor for MainThreadExecutor
impl SomeExecutor for MainThreadExecutor
Source§type ExecutorNotifier = Infallible
type ExecutorNotifier = Infallible
Design notes Read more
Source§fn spawn<F: Future + Send + 'static, Notifier: ObserverNotified<F::Output> + Send>(
&mut self,
task: Task<F, Notifier>,
) -> impl Observer<Value = F::Output>
fn spawn<F: Future + Send + 'static, Notifier: ObserverNotified<F::Output> + Send>( &mut self, task: Task<F, Notifier>, ) -> impl Observer<Value = F::Output>
Spawns a future onto the runtime. Read more
Source§async fn spawn_async<F: Future + Send + 'static, Notifier: ObserverNotified<F::Output> + Send>(
&mut self,
task: Task<F, Notifier>,
) -> impl Observer<Value = F::Output>
async fn spawn_async<F: Future + Send + 'static, Notifier: ObserverNotified<F::Output> + Send>( &mut self, task: Task<F, Notifier>, ) -> impl Observer<Value = F::Output>
Spawns a future onto the runtime. Read more
Source§fn spawn_objsafe(&mut self, task: ObjSafeTask) -> BoxedSendObserver
fn spawn_objsafe(&mut self, task: ObjSafeTask) -> BoxedSendObserver
Spawns a future onto the runtime. Read more
Source§fn spawn_objsafe_async<'s>(
&'s mut self,
task: ObjSafeTask,
) -> BoxedSendObserverFuture<'s>
fn spawn_objsafe_async<'s>( &'s mut self, task: ObjSafeTask, ) -> BoxedSendObserverFuture<'s>
Spawns a future onto the runtime. Read more
Source§fn executor_notifier(&mut self) -> Option<Self::ExecutorNotifier>
fn executor_notifier(&mut self) -> Option<Self::ExecutorNotifier>
Produces an executor notifier.
impl SomeExecutorExt for MainThreadExecutor
Source§impl SomeLocalExecutor<'static> for MainThreadExecutor
impl SomeLocalExecutor<'static> for MainThreadExecutor
Source§type ExecutorNotifier = Infallible
type ExecutorNotifier = Infallible
The notifier handle that can wake or signal work for this executor.
Source§fn spawn_local<F: Future + 'static, Notifier: ObserverNotified<F::Output>>(
&mut self,
task: Task<F, Notifier>,
) -> impl Observer<Value = F::Output>
fn spawn_local<F: Future + 'static, Notifier: ObserverNotified<F::Output>>( &mut self, task: Task<F, Notifier>, ) -> impl Observer<Value = F::Output>
Spawns a future onto the runtime. Read more
Source§fn spawn_local_async<F: Future + 'static, Notifier: ObserverNotified<F::Output>>(
&mut self,
task: Task<F, Notifier>,
) -> impl Future<Output = impl Observer<Value = F::Output>>
fn spawn_local_async<F: Future + 'static, Notifier: ObserverNotified<F::Output>>( &mut self, task: Task<F, Notifier>, ) -> impl Future<Output = impl Observer<Value = F::Output>>
Spawns a future onto the runtime. Read more
Source§fn spawn_local_objsafe(
&mut self,
task: Task<Pin<Box<dyn Future<Output = Box<dyn Any>>>>, Box<dyn ObserverNotified<dyn Any + 'static>>>,
) -> Box<dyn Observer<Output = FinishedObservation<Box<dyn Any + 'static>>, Value = Box<dyn Any + 'static>> + 'static>
fn spawn_local_objsafe( &mut self, task: Task<Pin<Box<dyn Future<Output = Box<dyn Any>>>>, Box<dyn ObserverNotified<dyn Any + 'static>>>, ) -> Box<dyn Observer<Output = FinishedObservation<Box<dyn Any + 'static>>, Value = Box<dyn Any + 'static>> + 'static>
Spawns a future onto the runtime. Read more
Source§fn spawn_local_objsafe_async<'s>(
&'s mut self,
task: Task<Pin<Box<dyn Future<Output = Box<dyn Any>>>>, Box<dyn ObserverNotified<dyn Any + 'static>>>,
) -> Box<dyn Future<Output = Box<dyn Observer<Output = FinishedObservation<Box<dyn Any + 'static>>, Value = Box<dyn Any + 'static>> + 'static>> + 's>
fn spawn_local_objsafe_async<'s>( &'s mut self, task: Task<Pin<Box<dyn Future<Output = Box<dyn Any>>>>, Box<dyn ObserverNotified<dyn Any + 'static>>>, ) -> Box<dyn Future<Output = Box<dyn Observer<Output = FinishedObservation<Box<dyn Any + 'static>>, Value = Box<dyn Any + 'static>> + 'static>> + 's>
Object-safe async variant of
Self::spawn_local_objsafe.Source§fn executor_notifier(&mut self) -> Option<Self::ExecutorNotifier>
fn executor_notifier(&mut self) -> Option<Self::ExecutorNotifier>
Returns an executor notifier when notification is supported.
Source§impl SomeStaticExecutor for MainThreadExecutor
impl SomeStaticExecutor for MainThreadExecutor
Source§type ExecutorNotifier = Box<dyn ExecutorNotified>
type ExecutorNotifier = Box<dyn ExecutorNotified>
The notifier handle that can wake or signal work for this executor.
Source§fn spawn_static<F: Future + 'static, Notifier: ObserverNotified<F::Output>>(
&mut self,
task: Task<F, Notifier>,
) -> impl Observer<Value = F::Output>
fn spawn_static<F: Future + 'static, Notifier: ObserverNotified<F::Output>>( &mut self, task: Task<F, Notifier>, ) -> impl Observer<Value = F::Output>
Spawns a static, non-Send future onto the runtime. Read more
Source§fn spawn_static_async<F: Future + 'static, Notifier: ObserverNotified<F::Output>>(
&mut self,
task: Task<F, Notifier>,
) -> impl Future<Output = impl Observer<Value = F::Output>>
fn spawn_static_async<F: Future + 'static, Notifier: ObserverNotified<F::Output>>( &mut self, task: Task<F, Notifier>, ) -> impl Future<Output = impl Observer<Value = F::Output>>
Spawns a static, non-Send future onto the runtime. Read more
Source§fn spawn_static_objsafe(
&mut self,
task: ObjSafeStaticTask,
) -> BoxedStaticObserver
fn spawn_static_objsafe( &mut self, task: ObjSafeStaticTask, ) -> BoxedStaticObserver
Spawns a static, non-Send future onto the runtime. Read more
Source§fn spawn_static_objsafe_async<'s>(
&'s mut self,
task: ObjSafeStaticTask,
) -> BoxedStaticObserverFuture<'s>
fn spawn_static_objsafe_async<'s>( &'s mut self, task: ObjSafeStaticTask, ) -> BoxedStaticObserverFuture<'s>
Spawns a static, non-Send future onto the runtime. Read more
Source§fn executor_notifier(&mut self) -> Option<Self::ExecutorNotifier>
fn executor_notifier(&mut self) -> Option<Self::ExecutorNotifier>
Produces an executor notifier.
Auto Trait Implementations§
impl Freeze for MainThreadExecutor
impl RefUnwindSafe for MainThreadExecutor
impl Send for MainThreadExecutor
impl Sync for MainThreadExecutor
impl Unpin for MainThreadExecutor
impl UnsafeUnpin for MainThreadExecutor
impl UnwindSafe for MainThreadExecutor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.