Skip to main content

MainThreadExecutor

Struct MainThreadExecutor 

Source
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

Source§

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)

Performs copy-assignment from source. Read more
Source§

impl Debug for MainThreadExecutor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl LocalExecutorExt<'static> for MainThreadExecutor

Source§

impl SomeExecutor for MainThreadExecutor

Source§

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>
where Self: Sized, F::Output: Send + Unpin,

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>
where Self: Sized, F::Output: Send + Unpin,

Spawns a future onto the runtime. Read more
Source§

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>

Spawns a future onto the runtime. Read more
Source§

fn clone_box(&self) -> Box<DynExecutor>

Clones the executor. Read more
Source§

fn executor_notifier(&mut self) -> Option<Self::ExecutorNotifier>

Produces an executor notifier.
Source§

fn block_on<F>(&mut self, future: F) -> <F as Future>::Output
where F: Future, Self: Sized, <F as Future>::Output: Send + 'static,

Drives future to completion on this executor, blocking the calling thread until it resolves. Read more
Source§

fn block_on_objsafe( &mut self, future: Pin<Box<dyn Future<Output = Box<dyn Any + Send>> + '_>>, ) -> Box<dyn Any + Send>

Drives a type-erased future to completion, blocking the calling thread. Read more
Source§

impl SomeExecutorExt for MainThreadExecutor

Source§

impl SomeLocalExecutor<'static> for MainThreadExecutor

Source§

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>
where Self: Sized, <F as Future>::Output: Unpin + 'static,

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>>
where Self: Sized, <F as Future>::Output: Unpin + 'static,

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>

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>

Object-safe async variant of Self::spawn_local_objsafe.
Source§

fn executor_notifier(&mut self) -> Option<Self::ExecutorNotifier>

Returns an executor notifier when notification is supported.
Source§

impl SomeStaticExecutor for MainThreadExecutor

Source§

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>
where Self: Sized, <F as Future>::Output: Unpin + 'static,

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>>
where Self: Sized, <F as Future>::Output: Unpin + 'static,

Spawns a static, non-Send future onto the runtime. Read more
Source§

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>

Spawns a static, non-Send future onto the runtime. Read more
Source§

fn clone_box(&self) -> Box<DynStaticExecutor>

Clones the executor. Read more
Source§

fn executor_notifier(&mut self) -> Option<Self::ExecutorNotifier>

Produces an executor notifier.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

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>

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)

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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more