pub struct AsyncApp { /* private fields */ }Expand description
前景 UI 协程持有的异步应用上下文(与 GPUI AsyncApp 对齐)。
!Send(绑定 UI 主线程),可自由跨 .await 存活并随时安全访问 PodPool、派生子任务、
发起 background_spawn 后台计算与 timer 定时器。
Implementations§
Source§impl AsyncApp
impl AsyncApp
Sourcepub fn background_executor(&self) -> BackgroundExecutor
pub fn background_executor(&self) -> BackgroundExecutor
获取绑定到当前引擎调度器后端的后台异步执行器句柄(用于 .spawn(...) / .timer(Duration))。
Sourcepub fn background_spawn<T, Fut>(&self, fut: Fut) -> Task<T> ⓘ
pub fn background_spawn<T, Fut>(&self, fut: Fut) -> Task<T> ⓘ
在当前引擎配置的后台调度器中执行 CPU 密集型计算或阻塞 I/O,返回可 .await 的 Task<T>。
Sourcepub fn timer(&self, duration: Duration) -> Timer ⓘ
pub fn timer(&self, duration: Duration) -> Timer ⓘ
创建由当前引擎调度器时钟驱动的非阻塞异步定时器(与 GPUI cx.background_executor().timer(dur) 等价简写)。
Sourcepub fn scheduler_name(&self) -> &'static str
pub fn scheduler_name(&self) -> &'static str
返回当前引擎配置的调度器名称。
Sourcepub fn spawn_for<V, T, F, Fut>(&self, handle: Handle<V>, f: F) -> Task<T> ⓘ
pub fn spawn_for<V, T, F, Fut>(&self, handle: Handle<V>, f: F) -> Task<T> ⓘ
在 UI 主线程前景执行器上为指定视图句柄派生绑定异步任务(闭包接收 (Handle<V>, AsyncApp))。
Sourcepub fn defer<F>(&self, f: F)where
F: FnOnce(&mut ActionScope<'_>) + 'static,
pub fn defer<F>(&self, f: F)where
F: FnOnce(&mut ActionScope<'_>) + 'static,
排入一个延迟到本轮前景调度末尾执行的 UI 主线程回调。
Sourcepub fn update<V: View, R>(
&mut self,
handle: Handle<V>,
f: impl FnOnce(&mut V, &mut ActionScope<'_>) -> R,
) -> Option<R>
pub fn update<V: View, R>( &mut self, handle: Handle<V>, f: impl FnOnce(&mut V, &mut ActionScope<'_>) -> R, ) -> Option<R>
在前景协程中安全更新任意 Handle<V> 视图的状态(自动校验 ABA generation、防重入、标脏并刷新信号)。
若目标视图已卸载或正在被可变借用,则安全返回 None 绝不 panic。
Sourcepub fn read<V: View, R>(
&self,
handle: Handle<V>,
f: impl FnOnce(&V) -> R,
) -> Option<R>
pub fn read<V: View, R>( &self, handle: Handle<V>, f: impl FnOnce(&V) -> R, ) -> Option<R>
在前景协程中只读读取任意 Handle<V> 视图的快照数据(若目标视图已卸载则返回 None)。
Sourcepub fn notify_handle<V: View>(&mut self, handle: Handle<V>)
pub fn notify_handle<V: View>(&mut self, handle: Handle<V>)
显式标记指定视图句柄为脏。
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for AsyncApp
impl !Send for AsyncApp
impl !Sync for AsyncApp
impl !UnwindSafe for AsyncApp
impl Forget for AsyncApp
impl Freeze for AsyncAppwhere
*const ArcInner<ForegroundShared> is !null: Freeze,
PhantomData<ArcInner<ForegroundShared>>: Freeze,
*const RcInner<RefCell<ForegroundLocal>> is !null: Freeze,
PhantomData<RcInner<RefCell<ForegroundLocal>>>: Freeze,
impl Move for AsyncApp
impl Unpin for AsyncApp
impl UnsafeUnpin for AsyncAppwhere
*const ArcInner<ForegroundShared> is !null: UnsafeUnpin,
PhantomData<ArcInner<ForegroundShared>>: UnsafeUnpin,
*const RcInner<RefCell<ForegroundLocal>> is !null: UnsafeUnpin,
PhantomData<RcInner<RefCell<ForegroundLocal>>>: UnsafeUnpin,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FluentBuilder for T
impl<T> FluentBuilder for T
Source§fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self
fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Self
当
condition 为 true 时执行闭包修饰自身,否则原样返回。Source§fn when_else(
self,
condition: bool,
then: impl FnOnce(Self) -> Self,
else_fn: impl FnOnce(Self) -> Self,
) -> Self
fn when_else( self, condition: bool, then: impl FnOnce(Self) -> Self, else_fn: impl FnOnce(Self) -> Self, ) -> Self
根据
condition 在两个修饰分支之间二选一。Source§fn when_some<O>(
self,
option: Option<O>,
then: impl FnOnce(Self, O) -> Self,
) -> Self
fn when_some<O>( self, option: Option<O>, then: impl FnOnce(Self, O) -> Self, ) -> Self
当
option 为 Some(value) 时执行闭包修饰自身,否则原样返回。